/** * @package DoceboLms * @version $Id: meta_certificate.php,v 1 * @author Marco Valloni <marco [at] docebo [dot] com> */ function metaCertificate() { checkPerm('view'); require_once _base_ . '/lib/lib.form.php'; require_once _base_ . '/lib/lib.table.php'; $mod_perm = checkPerm('mod', true); $lang =& DoceboLanguage::createInstance('certificate', 'lms'); $out =& $GLOBALS['page']; $out->setWorkingZone('content'); $tb = new Table(Get::sett('visuItem'), $lang->def('_META_CERTIFICATE_CAPTION'), $lang->def('_META_CERTIFICATE_SUMMARY')); $tb->initNavBar('ini', 'link'); $tb->setLink("index.php?modname=meta_certificate&op=meta_certificate"); $ini = $tb->getSelectedElement(); $form = new Form(); if (isset($_POST['toggle_filter'])) { unset($_POST['filter_text']); } //search query of certificates $query_certificate = "\r\n\tSELECT id_certificate, code, name, description\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_certificate" . " WHERE meta = 1"; if (isset($_POST['filter'])) { if ($_POST['filter_text'] !== '') { $query_certificate .= " AND ( name LIKE '%" . $_POST['filter_text'] . "%'" . " OR code LIKE '%" . $_POST['filter_text'] . "%' )"; } } $query_certificate .= " ORDER BY id_certificate\r\n\tLIMIT {$ini}," . Get::sett('visuItem'); $query_certificate_tot = "\r\n\tSELECT COUNT(*)\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_certificate"; $re_certificate = sql_query($query_certificate); list($tot_certificate) = sql_fetch_row(sql_query($query_certificate_tot)); $type_h = array('', '', '', 'image', 'image'); $cont_h = array($lang->def('_CODE'), $lang->def('_NAME'), $lang->def('_DESCRIPTION')); if ($mod_perm) { $cont_h[] = Lang::t('_TEMPLATE', 'certificate'); } $cont_h[] = '<img src="' . getPathImage() . 'standard/view.png" alt="' . $lang->def('_PREVIEW') . '" />'; if ($mod_perm) { $cont_h[] = Get::img('standard/moduser.png', Lang::t('_TITLE_ASSIGN_META_CERTIFICATE', 'certificate')); $type_h[] = 'image'; $cont_h[] = Get::sprite('subs_print', Lang::t('_TITLE_CREATE_META_CERTIFICATE', 'certificate')); $type_h[] = 'image'; $cont_h[] = '<img src="' . getPathImage() . 'standard/edit.png" title="' . $lang->def('_MOD') . '" ' . 'alt="' . $lang->def('_MOD') . '" />'; $type_h[] = 'image'; $cont_h[] = '<img src="' . getPathImage() . 'standard/delete.png" title="' . $lang->def('_DEL') . '" ' . 'alt="' . $lang->def('_DEL') . '"" />'; $type_h[] = 'image'; } $tb->setColsStyle($type_h); $tb->addHead($cont_h); while (list($id_certificate, $code, $name, $descr) = sql_fetch_row($re_certificate)) { $title = strip_tags($name); $cont = array($code, $name, Util::cut($descr)); if ($mod_perm) { $cont[] = '<a href="index.php?modname=meta_certificate&op=elemmetacertificate&id_certificate=' . $id_certificate . '" ' . 'title="' . Lang::t('_TEMPLATE', 'certificate') . '">' . Lang::t('_TEMPLATE', 'certificate') . '</a>'; } $cont[] = '<a href="index.php?modname=meta_certificate&op=preview&id_certificate=' . $id_certificate . '">' . '<img src="' . getPathImage() . 'standard/view.png" alt="' . $lang->def('_PREVIEW') . ' : ' . $title . '" /></a>'; if ($mod_perm) { $cont[] = '<a href="index.php?modname=meta_certificate&op=assign&id_certificate=' . $id_certificate . '" ' . 'title="' . $lang->def('_TITLE_ASSIGN_META_CERTIFICATE') . ' : ' . $name . '">' . Get::img('standard/moduser.png', Lang::t('_TITLE_ASSIGN_META_CERTIFICATE', 'certificate')) . '</a>'; /* $cont[] = '<a href="index.php?modname=meta_certificate&op=create&id_certificate='.$id_certificate.'" ' .'title="'.$lang->def('_TITLE_CREATE_META_CERTIFICATE').' : '.$name.'">' .Get::img('course/certificate.png', Lang::t('_TITLE_CREATE_META_CERTIFICATE', 'certificate')) .'</a>';*/ $cont[] = Get::sprite_link('subs_print', 'index.php?modname=meta_certificate&op=create&id_certificate=' . $id_certificate, Lang::t('_TITLE_CREATE_META_CERTIFICATE', 'certificate')); $cont[] = '<a href="index.php?modname=meta_certificate&op=modmetacertificate&id_certificate=' . $id_certificate . '" ' . 'title="' . $lang->def('_MOD') . ' : ' . $name . '">' . '<img src="' . getPathImage() . 'standard/edit.png" alt="' . $lang->def('_MOD') . ' : ' . $title . '" /></a>'; $cont[] = '<a href="index.php?modname=meta_certificate&op=delmetacertificate&id_certificate=' . $id_certificate . '" ' . 'title="' . $lang->def('_DEL') . ' : ' . $name . '">' . '<img src="' . getPathImage() . 'standard/delete.png" alt="' . $lang->def('_DEL') . ' : ' . $title . '" /></a>'; } $tb->addBody($cont); } require_once _base_ . '/lib/lib.dialog.php'; setupHrefDialogBox('a[href*=delmetacertificate]'); if ($mod_perm) { $tb->addActionAdd('<a class="ico-wt-sprite subs_add" href="index.php?modname=meta_certificate&op=addmetacertificate" title="' . $lang->def('_NEW_CERTIFICATE') . '"><span>' . $lang->def('_NEW_CERTIFICATE') . '</span></a>'); } $out->add(getTitleArea($lang->def('_TITLE_META_CERTIFICATE'), 'certificate') . '<div class="std_block">'); $out->add($form->openForm('certificate_filter', 'index.php?modname=meta_certificate&op=meta_certificate') . '<div class="quick_search_form"> <div> <div class="simple_search_box">' . Form::getInputTextfield("search_t", "filter_text", "filter_text", Get::req('filter_text', DOTY_MIXED, ''), '', 255, '') . Form::getButton("filter", "filter", Lang::t('_SEARCH', 'standard'), "search_b") . Form::getButton("toggle_filter", "toggle_filter", Lang::t('_RESET', 'standard'), "reset_b") . '</div> </div> </div>' . $form->closeForm()); if (isset($_GET['result'])) { switch ($_GET['result']) { case "ok": $out->add(getResultUi($lang->def('_OPERATION_SUCCESSFUL'))); break; case "err": $out->add(getErrorUi($lang->def('_OPERATION_FAILURE'))); break; case "err_del": $out->add(getErrorUi($lang->def('_OPERATION_FAILURE'))); break; } } $out->add($tb->getTable() . $tb->getNavBar($ini, $tot_certificate) . '</div>'); }
function view_report_certificate() { checkPerm('view'); require_once _lms_ . '/lib/lib.certificate.php'; require_once _lms_ . '/lib/lib.course.php'; $out =& $GLOBALS['page']; $out->setWorkingZone('content'); $lang =& DoceboLanguage::createInstance('certificate', 'lms'); $deletion = importVar('deletion', true, 0); if ($deletion) { switch ($deletion) { case 1: $out->add(getResultUi($lang->def('_OPERATION_SUCCESSFUL'))); break; case 2: $out->add(getErrorUi($lang->def('_OPERATION_FAILURE'))); break; case 3: $out->add(getErrorUi($lang->def('_OPERATION_FAILURE'))); break; } } $certificate = new Certificate(); $id_certificate = importVar('id_certificate', true, 0); $id_course = importVar('id_course', true, 0); $selection = importVar('selection', false, array()); //all possible selected values $selected = importVar('selected', false, array()); //effectively selected values with checkbox $sel = importVar('old_selection', false, ''); //selected values from previous table pages if ($sel != '') { $total_selection = explode(',', $sel); } else { $total_selection = array(); } //update total selection foreach ($selection as $key => $val) { if (in_array($val, $selected)) { if (!in_array($val, $total_selection)) { $total_selection[] = $val; } } else { $index = array_search($val, $total_selection); if ($index !== false) { array_splice($total_selection, $index, 1); } } } $search_filter = importVar('filter', false, ''); $only_released = importVar('only_released', true, 0); //which command? if (importVar('search_button', false, false) !== false) { } if (importVar('reset_button', false, false) !== false) { $search_filter = ''; $only_released = 0; } if (importVar('print_button', false, false) !== false) { } $numtablerows = Get::sett('visuItem', 25); $tb = new Table($numtablerows, $lang->def('_CERTIFICATE_VIEW_CAPTION'), $lang->def('_CERTIFICATE_VIEW_CAPTION')); $tb->initNavBar('ini', 'button'); $ini = $tb->getSelectedElement(); $ini_param = Get::req('ini', DOTY_MIXED, array()); //floor($ini / Get::sett('visuItem', 25)); if (empty($ini_param)) { $ini_param = 1; } else { list($ini_param) = each($ini_param); } $tca = $GLOBALS['prefix_lms'] . "_certificate_assign as ca"; $tcc = $GLOBALS['prefix_lms'] . "_certificate_course as cc"; $tcu = $GLOBALS['prefix_lms'] . "_courseuser as cu"; $tu = $GLOBALS['prefix_fw'] . "_user as u"; $where = ""; if ($search_filter != '') { $where .= " AND (u.userid LIKE '%" . $search_filter . "%' OR u.lastname LIKE '%" . $search_filter . "%' OR u.firstname LIKE '%" . $search_filter . "%') "; } if ($only_released > 0) { $where = " AND ca.on_date " . ($only_released == 1 ? "IS NOT" : "IS") . " NULL "; } //$where .= " AND ".$aval_status." ".($only_released==1 ? "<" : ">=")." cu.status "; list($aval_status) = sql_fetch_row(sql_query("SELECT available_for_status FROM " . $tcc . " " . " WHERE id_certificate='" . (int) $id_certificate . "' AND id_course='" . (int) $id_course . "'")); switch ($aval_status) { case AVS_ASSIGN_FOR_ALL_STATUS: $aval_status = " 1 "; break; case AVS_ASSIGN_FOR_STATUS_INCOURSE: $aval_status = " cu.status = " . _CUS_BEGIN . " "; break; case AVS_ASSIGN_FOR_STATUS_COMPLETED: $aval_status = " cu.status = " . _CUS_END . " "; break; } list($totalrows) = sql_fetch_row(sql_query("SELECT COUNT(*) " . " FROM ( " . $tu . " JOIN " . $tcu . " ON (u.idst = cu.idUser) ) LEFT JOIN " . $tca . " " . " ON ( ca.id_course = cu.idCourse AND ca.id_user=cu.idUser ) " . " WHERE (ca.id_certificate='" . (int) $id_certificate . "' OR ca.id_certificate IS NULL) AND " . $aval_status . " " . " AND cu.idCourse='" . (int) $id_course . "' " . $where)); $query = "SELECT u.userid, u.firstname, u.lastname, cu.date_complete, ca.on_date, cu.idUser as id_user, cu.status " . " FROM ( " . $tu . " JOIN " . $tcu . " ON (u.idst = cu.idUser) ) LEFT JOIN " . $tca . " " . " ON ( ca.id_course = cu.idCourse AND ca.id_user=cu.idUser ) " . " WHERE (ca.id_certificate='" . (int) $id_certificate . "' OR ca.id_certificate IS NULL) AND " . $aval_status . " " . " AND cu.idCourse='" . (int) $id_course . "' " . $where . " ORDER BY u.userid LIMIT " . $ini . ", " . $numtablerows; //cout('<pre>'.print_r($_POST, true).'</pre>'); //cout($query); $res = sql_query($query); $from = Get::req('from', DOTY_MIXED, ''); if ($from === 'course') { $back_ui = getBackUi('index.php?r=alms/course/certificate&id_course=' . (int) $id_course, $lang->def('_BACK')); $out->add(getTitleArea(array('index.php?r=alms/course/certificate&id_course=' . (int) $id_course => $lang->def('_CERTIFICATE_ASSIGN_STATUS', 'course'), $lang->def('_COURSES')), 'certificate')); } else { $back_ui = getBackUi('index.php?modname=certificate&op=report_certificate&id_certificate=' . (int) $id_certificate, $lang->def('_BACK')); $out->add(getTitleArea(array('index.php?modname=certificate&op=certificate' => $lang->def('_TITLE_CERTIFICATE'), 'index.php?modname=certificate&op=report_certificate&id_certificate=' . (int) $id_certificate => $lang->def('_COURSES'), $lang->def('_CERTIFICATE_VIEW_CAPTION')), 'certificate')); } $out->add('<div class="std_block">' . $back_ui); $numrows = sql_num_rows($res); $downloadables = array(); if ($numrows > 0) { $clang =& DoceboLanguage::CreateInstance('course', 'lms'); $type_h = array('image', '', '', '', '', '', '', 'image', 'image'); $cont_h = array('', $lang->def('_USERNAME'), $lang->def('_LASTNAME'), $lang->def('_FIRSTNAME'), $clang->def('_STATUS'), $lang->def('_DATE'), $lang->def('_RELASE_DATE'), Get::sprite('subs_pdf', Lang::t('_TITLE_VIEW_CERT', 'certificate')), Get::sprite('subs_del', Lang::t('_DEL', 'certificate'))); $tb->setColsStyle($type_h); $tb->addHead($cont_h); $acl_man =& $GLOBALS['current_user']->getAclManager(); $arr_status = array(_CUS_CONFIRMED => $clang->def('_USER_STATUS_CONFIRMED'), _CUS_SUBSCRIBED => $clang->def('_USER_STATUS_SUBS'), _CUS_BEGIN => $clang->def('_USER_STATUS_BEGIN'), _CUS_END => $clang->def('_USER_STATUS_END'), _CUS_SUSPEND => $clang->def('_USER_STATUS_SUSPEND')); //foreach($report_info as $info_report) while ($info = sql_fetch_assoc($res)) { $cont = array(); $can_assign = (bool) ($info['on_date'] == ''); $input_id = $info['id_user']; $sel_cell_content = ''; $label_open = ''; $label_close = ''; if ($can_assign) { $input = '<input type="hidden" id="selection_' . $input_id . '" name="selection[' . $input_id . ']" value="' . $input_id . '"/> '; if (in_array($input_id, $total_selection)) { $checked = ' checked="checked"'; } else { $checked = ''; } $sel_cell_content .= $input . '<input type="checkbox" id="selected_' . $input_id . '" name="selected[' . $input_id . ']" value="' . $input_id . '"' . $checked . '/>'; $label_open = '<label for="selected_' . $input_id . '">'; $label_close = '</label>'; } $userid = $acl_man->relativeId($info['userid']); $cont[] = $sel_cell_content; $cont[] = $label_open . ($search_filter != '' ? highlightText($userid, $search_filter) : $userid) . $label_close; $cont[] = $label_open . ($search_filter != '' ? highlightText($info['lastname'], $search_filter) : $info['lastname']) . $label_close; $cont[] = $label_open . ($search_filter != '' ? highlightText($info['firstname'], $search_filter) : $info['firstname']) . $label_close; $cont[] = $arr_status[$info['status']]; $cont[] = $info['date_complete']; $cont[] = $info['on_date']; $url = 'index.php?modname=certificate&certificate_id=' . $id_certificate . '&course_id=' . $id_course . '&user_id=' . $info['id_user']; $dl_url = $url . "&op=send_certificate"; if ($can_assign) { $downloadables[] = 'dl_single_' . $input_id; } $cont[] = $can_assign ? '<a id="dl_single_' . $input_id . '" class="ico-wt-sprite subs_pdf" href="javascript:;" title="' . $lang->def('_GENERATE') . '"><span>' . $lang->def('_GENERATE') . '</span></a>' : '<a id="dl_single_' . $input_id . '" class="ico-wt-sprite subs_pdf" href="' . $dl_url . '" title="' . $lang->def('_DOWNLOAD') . '"><span>' . $lang->def('_DOWNLOAD') . '</span></a>'; $cont[] = $can_assign ? '' : Get::sprite_link('subs_del', $url . '&op=del_report_certificate', Lang::t('_DEL', 'certificate')); $tb->addBody($cont); } require_once _base_ . '/lib/lib.dialog.php'; setupHrefDialogBox('a[href*=del_report_certificate]'); //search filter ... $release_options = array($lang->def('_ALL') => 0, $lang->def('_RELEASED') => 1, $lang->def('_TO_RELEASE') => 2); //search and store all non-available certificates $all_selection = array(); $query = "SELECT cu.idUser as id_user " . " FROM ( " . $tu . " JOIN " . $tcu . " ON (u.idst = cu.idUser) ) LEFT JOIN " . $tca . " " . " ON ( ca.id_course = cu.idCourse AND ca.id_user=cu.idUser ) " . " WHERE (ca.id_certificate='" . (int) $id_certificate . "' OR ca.id_certificate IS NULL) AND " . $aval_status . " " . " AND cu.idCourse='" . (int) $id_course . "' " . ($search_filter != '' ? " AND (u.userid LIKE '%" . $search_filter . "%' OR u.lastname LIKE '%" . $search_filter . "%' OR u.firstname LIKE '%" . $search_filter . "%') " : "") . " AND ca.on_date IS NULL "; $res = sql_query($query); while (list($id_user) = sql_fetch_row($res)) { $all_selection[] = $id_user; } //--- $form = new Form(); $submit_url = "index.php?modname=certificate&op=view_report_certificate&id_certificate=" . (int) $id_certificate . "&id_course=" . (int) $id_course; $out->add($form->openForm("certificates_emission", $submit_url) . $form->getHidden('old_selection', 'old_selection', implode(',', $total_selection)) . $form->getHidden('all_selection', 'all_selection', implode(',', $all_selection)) . $form->getHidden('active_text_filter', 'active_text_filter', $search_filter) . $form->getHidden('active_only_released', 'active_only_released', $only_released) . $form->getHidden('active_ini', 'active_ini', $ini_param) . '<div class="quick_search_form">' . '<div class="simple_search_box">' . Form::getInputTextfield("search_t", "filter", "filter", $search_filter, '', 255, '') . Form::getButton("search_button", "search_button", Lang::t('_SEARCH', 'standard'), "search_b") . Form::getButton("reset_button", "reset_button", Lang::t('_RESET', 'standard'), "reset_b") . '</div>' . '<a id="advanced_search" class="advanced_search" href="javascript:;">' . Lang::t("_ADVANCED_SEARCH", 'standard') . '</a>' . '<div id="certificate_release_as" class="advanced_search_options" style="display: ' . ($only_released != 0 ? 'block' : 'none') . '">' . Form::getRadioHoriz(Lang::t('_FILTER', 'certificate'), 'only_released', 'only_released', $release_options, $only_released) . '</div>' . '</div>' . '<script type="text/javascript">' . 'YAHOO.util.Event.addListener("advanced_search", "click", function(e){ var el = YAHOO.util.Dom.get("certificate_release_as"); if (el.style.display != \'block\') el.style.display = \'block\'; else el.style.display = \'none\'; });' . '</script>', 'content'); $delgen_url = 'index.php?modname=certificate&op=del_gen_certificate' . '&id_certificate=' . (int) $id_certificate . '&id_course=' . (int) $id_course; $delgen_txt = Lang::t('_DELETE_ALL_GENERATED', 'certificate'); $print_button_1 = '<div>' . '<a id="print_selected_button_1" href="javascript:;">' . Get::img('course/certificate.png', Lang::t('_GENERATE_ALL_SELECTED', 'certificate')) . Lang::t('_GENERATE_ALL_SELECTED', 'certificate') . '</a>' . '</div>'; $print_button_2 = '<div><a id="print_selected_button_2" href="javascript:;">' . Get::img('course/certificate.png', Lang::t('_GENERATE_ALL_SELECTED', 'certificate')) . Lang::t('_GENERATE_ALL_SELECTED', 'certificate') . '</a>' . '</div>'; $print_button_1 .= Lang::t('_SELECT', 'directory') . ': '; $print_button_2 .= Lang::t('_SELECT', 'directory') . ': '; /* $print_button_1 .= ' <a href="javascript:;" id="select_page_1">'.Lang::t('_SELECT_PAGE', 'standard').'</a>'; $print_button_2 .= ' <a href="javascript:;" id="select_page_2">'.Lang::t('_SELECT_PAGE', 'standard').'</a>'; $print_button_1 .= ' <a href="javascript:;" id="unselect_page_1">'.Lang::t('_UNSELECT_PAGE', 'standard').'</a>'; $print_button_2 .= ' <a href="javascript:;" id="unselect_page_2">'.Lang::t('_UNSELECT_PAGE', 'standard').'</a>'; */ $print_button_1 .= ' <a href="javascript:;" id="select_all_1">' . Lang::t('_ALL_PAGES', 'directory') . '</a>'; $print_button_2 .= ' <a href="javascript:;" id="select_all_2">' . Lang::t('_ALL_PAGES', 'directory') . '</a>'; $print_button_1 .= ' <a href="javascript:;" id="unselect_all_1">' . Lang::t('_NONE', 'directory') . '</a>'; $print_button_2 .= ' <a href="javascript:;" id="unselect_all_2">' . Lang::t('_NONE', 'directory') . '</a>'; $navbar = $tb->getNavBar($ini, $totalrows); $out->add($print_button_1 . '<br />' . $navbar . $tb->getTable() . $navbar . '<br />' . $print_button_2); $out->add($form->closeForm()); } else { $out->add($lang->def('_NO_CONTENT')); } $out->add($back_ui . '</div>'); addCss('style_menu', 'lms'); Util::get_js(Get::rel_path('base') . '/widget/dialog/dialog.js', true, true); Util::get_js(Get::rel_path('lms') . '/admin/modules/certificate/certificate.js?rnd=' . time(), true, true); //addJs($GLOBALS['where_lms_relative'].'/admin/modules/certificate/', 'certificate.js'); $script = 'var ajax_url="ajax.adm_server.php?plf=lms&mn=certificate"; var _STOP="' . $lang->def('_STOP') . '"; ' . 'var glob_id_certificate = ' . (int) $id_certificate . ', glob_id_course = ' . (int) $id_course . ';' . 'var single_list = [' . (count($downloadables) ? '"' . implode('","', $downloadables) . '"' : '') . ']; ' . 'var reload_url = "' . str_replace('&', '&', isset($submit_url) ? $submit_url : '') . '", ' . '_ERROR_PARSE = "' . $lang->def('_OPERATION_FAILURE') . '", _SUCCESS = "' . $lang->def('_OPERATION_SUCCESSFUL') . '", ' . '_AREYOUSURE="' . Lang::t('_AREYOUSURE', 'standard') . '";'; $out->add('<script type="text/javascript">' . $script . '</script>', 'page_head'); }