Exemple #1
0
def detil_surat_sakit_sekre(id):
    if(get_session_state() == False):
        return redirect(url_for('auth.login'))

    nama_user = session['user_name']
    role_user = session['role']

    if(role_user != 'sekre'):
        flash('Halaman tidak bisa diakses oleh mahasiswa')
        return redirect(url_for('sisukit.list_surat_sakit_mahasiswa'))

    db = get_db()
    db.row_factory = dict_factory
    cur = db.cursor()
    surat = cur.execute(
        'SELECT * FROM surat_sakit WHERE id=?',(id,))
    srt = surat.fetchall()
    detail = cur.execute(
        'SELECT * FROM detail_surat_sakit WHERE id_surat_sakit=?',(id,))
    dtl = detail.fetchall()
    detail.close()

    list_param = [nama_user,role_user,srt,dtl]

    return render_template('detail-surat-sekre.html', list_param = list_param)
Exemple #2
0
def kirim_surat_sakit():
    if(get_session_state() == False):
        return redirect(url_for('auth.login'))

    today = date.today()
    nama_user = session['user_name']
    role_user = session['role']
    npm = session['kode_identitas']

    if(role_user != 'mahasiswa'):
        flash('Halaman tidak bisa diakses oleh sekretariat')
        return redirect(url_for('sisukit.list_surat_sakit_sekre'))

    list_param = [nama_user,role_user,today]
    if request.method == 'POST':
        tanggal_submit = request.form['tanggal_submit']
        nama_penyakit = request.form['nama_penyakit']
        tanggal_izin = request.form['tanggal_izin']
        nama_mata_kuliah = request.form.getlist('mata_kuliah_izin')
        nama_dosen = request.form.getlist('dosen_mata_kuliah')
        print(request.form.getlist('mata_kuliah_izin'))
        print(request.form.getlist('dosen_mata_kuliah'))

        db = get_db()
        error = None
     
        if 'dokumen_surat_sakit' not in request.files:
            flash('Tidak ada form dokumen surat sakit')
            return redirect(request.url)

        file = request.files['dokumen_surat_sakit']

        if file.filename == '':
            flash('Masukkan surat sakit')
            return redirect(request.url)
        
        if file and allowed_file(file.filename):
            extension = file.filename.rsplit('.',1)[1].lower()
            filename = secure_filename(nama_user+npm+nama_penyakit+tanggal_izin)
            surat = db.execute(
                'INSERT INTO surat_sakit (nama_mahasiswa, npm, tanggal_upload, surat_sakit_mahasiswa, status_surat_sakit, nama_penyakit, tanggal_izin) VALUES (?,?,?,?,?,?,?)',
                (nama_user, npm, tanggal_submit,filename+'.'+extension,'submitted',nama_penyakit,tanggal_izin)#change to real NPM after connect to UI API
            )   
            id_surat = surat.lastrowid

            for i in range (len(nama_mata_kuliah)):
                print(nama_mata_kuliah[i])
                print(nama_dosen[i])
                detail = db.execute(
                    'INSERT INTO detail_surat_sakit (id_surat_sakit,mata_kuliah_izin,nama_dosen_izin) VALUES (?,?,?)',
                    (id_surat, nama_mata_kuliah[i],nama_dosen[i])
                )

            file.save(os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], (filename+'.'+extension)))# Windows OS
            db.commit()
            return redirect(url_for('sisukit.list_surat_sakit_mahasiswa'))


    return render_template('kirim-surat-sakit.html', list_param = list_param)    
Exemple #3
0
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = get_db().execute('SELECT * FROM user WHERE id = ?',
                                  (user_id, )).fetchone()
Exemple #4
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']

        access_token = get_access_token(username, password)
        if access_token is not None:
            ver_user = verify_user(access_token)
            kode_identitas = ver_user['identity_number']
            role = ver_user['role']
            session.clear()
            session['user_name'] = username
            session['access_token'] = access_token
            session['kode_identitas'] = kode_identitas
            session['role'] = role
            if role == 'mahasiswa':
                return redirect(url_for('sisukit.list_surat_sakit_mahasiswa'))
        else:
            print('pass sso salah')
            db = get_db()
            error = None
            user = db.execute('SELECT * FROM user WHERE username = ?',
                              (username, )).fetchone()

            if user is None:
                error = 'Username salah'
                flash(error)
                return render_template('login.html')

            if password != user['password']:
                error = 'Password salah'
                flash(error)
                return render_template('login.html')

            if error is None:
                session.clear()
                session['user_name'] = user['username']
                session['kode_identitas'] = user['kode']
                session['role'] = user['role']
                session['access_token'] = '-'
                if user['role'] == 'sekre':
                    print('sekre berhasil login')
                    return redirect(url_for('sisukit.list_surat_sakit_sekre'))

    return render_template('login.html')
Exemple #5
0
def list_surat_sakit_sekre():
    if(get_session_state() == False):
        return redirect(url_for('auth.login'))

    nama_user = session['user_name']
    role_user = session['role']

    if(role_user != 'sekre'):
        flash('Halaman tidak bisa diakses oleh mahasiswa')
        return redirect(url_for('sisukit.list_surat_sakit_mahasiswa'))

    list_surat = []
    db = get_db()
    surat = db.execute(
        'SELECT * FROM surat_sakit')#now by username then by NPM
    list_surat = surat
    list_param = [nama_user,role_user,list_surat]
    return render_template('list-surat-sekre.html', list_param = list_param)
Exemple #6
0
def terima_surat_sakit(id):
    if(get_session_state() == False):
        return redirect(url_for('auth.login'))

    nama_user = session['user_name']
    role_user = session['role']

    if(role_user != 'sekre'):
        flash('Halaman tidak bisa diakses oleh mahasiswa')
        return redirect(url_for('sisukit.list_surat_sakit_mahasiswa'))    

    today = date.today()
    db = get_db()
    surat = db.execute("""UPDATE surat_sakit
                  SET status_surat_sakit=?, disetujui_oleh=?, ditolak_oleh=?, tanggal_pengubahan_status=?, keterangan=?
                  WHERE id=?;""",
               ('Diterima',nama_user+'-'+role_user,'-',today,'-',id))
    db.commit()
    flash("Surat sakit berhasil diterima")
    list_param = [nama_user,role_user]

    return redirect(url_for('sisukit.detil_surat_sakit_sekre',id=id))