Example #1
0
function openid_form()
{
    $form = new FormValidator('openid_login', 'post', null, null, array('class' => 'form-vertical form_login'));
    $form->addElement('text', 'openid_url', array(get_lang('OpenIDURL'), Display::url(get_lang('OpenIDWhatIs'), 'main/auth/openid/whatis.php')), array('class' => 'openid_input'));
    $form->addElement('button', 'submit', get_lang('Login'));
    return $form->return_form();
}
 /**
  * @param string $url
  * @return \FormValidator
  */
 private function getSearchForm($url)
 {
     $form = new \FormValidator('search-form', 'get', $url, null, array('class' => 'form-inline'));
     $form->addElement('text', 'keyword');
     $form->addElement('button', 'submit', get_lang('Search'));
     return $form;
 }
 /**
  * @return FormValidator
  */
 private function getSearchForm()
 {
     $form = new FormValidator('form-search', 'post', api_get_self() . '?action=subscribe&hidden_links=0', null, array('class' => 'form-search'));
     $form->addElement('hidden', 'search_course', '1');
     $form->addElement('text', 'search_term');
     $form->addElement('button', 'submit', get_lang('Search'));
     return $form;
 }
function lp_upload_quiz_main()
{
    // variable initialisation
    $lp_id = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : null;
    $form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id=' . $lp_id, '', array('enctype' => 'multipart/form-data'));
    $form->addElement('header', get_lang('ImportExcelQuiz'));
    $form->addElement('file', 'user_upload_quiz', get_lang('FileUpload'));
    $link = '<a href="../exercice/quiz_template.xls">' . Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')) . get_lang('DownloadExcelTemplate') . '</a>';
    $form->addElement('label', '', $link);
    $table = new HTML_Table(array('class' => 'table'));
    $tableList = array(UNIQUE_ANSWER => get_lang('UniqueSelect'), MULTIPLE_ANSWER => get_lang('MultipleSelect'), FILL_IN_BLANKS => get_lang('FillBlanks'), MATCHING => get_lang('Matching'), FREE_ANSWER => get_lang('FreeAnswer'), GLOBAL_MULTIPLE_ANSWER => get_lang('GlobalMultipleAnswer'));
    $table->setHeaderContents(0, 0, get_lang('QuestionType'));
    $table->setHeaderContents(0, 1, '#');
    $row = 1;
    foreach ($tableList as $key => $label) {
        $table->setCellContents($row, 0, $label);
        $table->setCellContents($row, 1, $key);
        $row++;
    }
    $table = $table->toHtml();
    $form->addElement('label', get_lang('QuestionType'), $table);
    $form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id' => 'user_custom_score'));
    $form->addElement('html', '<div id="options" style="display:none">');
    $form->addElement('text', 'correct_score', get_lang('CorrectScore'));
    $form->addElement('text', 'incorrect_score', get_lang('IncorrectScore'));
    $form->addElement('html', '</div>');
    $form->addRule('user_upload_quiz', get_lang('ThisFieldIsRequired'), 'required');
    $form->add_progress_bar();
    $form->addButtonUpload(get_lang('Upload'), 'submit_upload_quiz');
    // Display the upload field
    $form->display();
}
Example #5
0
/**
 * This function displays the form for import of the zip file with qti2
 */
function ch_qti2_display_form()
{
    $name_tools = get_lang('ImportQtiQuiz');
    $form = '<div class="actions">';
    $form .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'exercice/exercise.php?show=test&' . api_get_cidreq() . '">' . Display::return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM) . '</a>';
    $form .= '</div>';
    $formValidator = new FormValidator('qti_upload', 'post', api_get_self() . "?" . api_get_cidreq(), null, array('enctype' => 'multipart/form-data'));
    $formValidator->addElement('header', $name_tools);
    $formValidator->addElement('file', 'userFile', get_lang('DownloadFile'));
    $formValidator->addButtonImport(get_lang('Upload'));
    $form .= $formValidator->returnForm();
    echo $form;
}
function lp_upload_quiz_main()
{
    // variable initialisation
    $lp_id = Security::remove_XSS($_GET['lp_id']);
    $form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id=' . $lp_id, '', array('enctype' => 'multipart/form-data'));
    $form->addElement('header', get_lang('ImportExcelQuiz'));
    $form->addElement('file', 'user_upload_quiz', get_lang('FileUpload'));
    $link = '<a href="../exercice/quiz_template.xls">' . Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate'), null, 16) . get_lang('DownloadExcelTemplate');
    $form->addElement('advanced_settings', $link);
    //button send document
    $form->addElement('style_submit_button', 'submit_upload_quiz', get_lang('Send'), 'class="upload"');
    // Display the upload field
    $form->display();
}
Example #7
0
function openid_form()
{
    //get_lang('OpenIdAuthentication')
    $form = new FormValidator('openid_login', 'post', null, null, array('class' => 'form-vertical form_login'));
    $form->addElement('text', 'openid_url', array(get_lang('OpenIDURL'), Display::url(get_lang('OpenIDWhatIs'), 'main/auth/openid/whatis.php')), array('class' => 'openid_input'));
    $form->addElement('button', 'submit', get_lang('Login'));
    return $form->return_form();
    /*
     return '<label for="openid_url">'.get_lang('OpenIDURL').' <a href="main/auth/openid/whatis.php" title="'.get_lang('OpenIDWhatIs').'">'.Display::return_icon('info3.gif',get_lang('Info')).'</a></label>
     <input type="text" id="openid_url" name="openid_url" style="background: url(main/img/openid_small_logo.png) no-repeat; background-color: #fff; background-position: 0 50%; padding-left:18px;" value="http://"></input>
    * <input type="submit" name="openid_login" value="'.get_lang('Enter').'" /><br /><br /></form></div>';
    *
    */
}
/**
 * This function displays the form for import of the zip file with qti2
 * @param   string  Report message to show in case of error
 */
function aiken_display_form($msg = '')
{
    $name_tools = get_lang('ImportAikenQuiz');
    $form = '<div class="actions">';
    $form .= '<a href="exercice.php?show=test">' . Display::return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM) . '</a>';
    $form .= '</div>';
    $form .= $msg;
    $form_validator = new FormValidator('aiken_upload', 'post', api_get_self() . "?" . api_get_cidreq(), null, array('enctype' => 'multipart/form-data'));
    $form_validator->addElement('header', $name_tools);
    $form_validator->addElement('text', 'total_weight', get_lang('TotalWeight'));
    $form_validator->addElement('file', 'userFile', get_lang('DownloadFile'));
    $form_validator->addElement('style_submit_button', 'submit', get_lang('Send'), 'class="upload"');
    $form .= $form_validator->return_form();
    $form .= '<blockquote>' . get_lang('ImportAikenQuizExplanation') . '<br /><pre>' . get_lang('ImportAikenQuizExplanationExample') . '</pre></blockquote>';
    echo $form;
}
 /**
  * function which redefine Question::createAnswersForm
  * @param FormValidator $form
  */
 function createAnswersForm($form)
 {
     $form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1'));
     global $text, $class;
     // setting the save button here and not in the question class.php
     $form->addButtonSave($text, 'submitQuestion');
     if (!empty($this->id)) {
         $form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
     } else {
         if ($this->isContent == 1) {
             $form->setDefaults(array('weighting' => '10'));
         }
     }
 }
 /**
  * Returns a Form validator Obj
  * @param   string  $url
  * @param   string  $action add, edit
  *
  * @return  FormValidator
  */
 public function return_form($url, $action)
 {
     $form = new FormValidator('career', 'post', $url);
     // Setting the form elements
     $header = get_lang('Add');
     if ($action == 'edit') {
         $header = get_lang('Modify');
     }
     $form->addElement('header', $header);
     $id = isset($_GET['id']) ? intval($_GET['id']) : '';
     $form->addElement('hidden', 'id', $id);
     $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
     $form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers', 'Width' => '100%', 'Height' => '250'));
     $status_list = $this->get_status_list();
     $form->addElement('select', 'status', get_lang('Status'), $status_list);
     if ($action == 'edit') {
         $form->addElement('text', 'created_at', get_lang('CreatedAt'));
         $form->freeze('created_at');
     }
     if ($action == 'edit') {
         $form->addButtonSave(get_lang('Modify'), 'submit');
     } else {
         $form->addButtonCreate(get_lang('Add'), 'submit');
     }
     // Setting the defaults
     $defaults = $this->get($id);
     if (!empty($defaults['created_at'])) {
         $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
     }
     if (!empty($defaults['updated_at'])) {
         $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
     }
     $form->setDefaults($defaults);
     // Setting the rules
     $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     return $form;
 }
function lp_upload_quiz_main()
{
    // variable initialisation
    $lp_id = isset($_GET['lp_id']) ? Security::remove_XSS($_GET['lp_id']) : null;
    $form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id=' . $lp_id, '', array('enctype' => 'multipart/form-data'));
    $form->addElement('header', get_lang('ImportExcelQuiz'));
    $form->addElement('file', 'user_upload_quiz', get_lang('FileUpload'));
    $link = '<a href="../exercice/quiz_template.xls">' . Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')) . get_lang('DownloadExcelTemplate') . '</a>';
    $form->addElement('advanced_settings', $link);
    $form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id' => 'user_custom_score'));
    $form->addElement('html', '<div id="options" style="display:none">');
    $form->addElement('text', 'correct_score', get_lang('CorrectScore'));
    $form->addElement('text', 'incorrect_score', get_lang('IncorrectScore'));
    $form->addElement('html', '</div>');
    $form->addRule('user_upload_quiz', get_lang('ThisFieldIsRequired'), 'required');
    $form->add_progress_bar();
    $form->addElement('style_submit_button', 'submit_upload_quiz', get_lang('Send'), 'class="upload"');
    // Display the upload field
    $form->display();
}
 /**
  * Create a form validator based on an array of form data:
  *
  *         array(
  *             'name' => 'zombie_report_parameters',    //optional
  *             'method' => 'GET',                       //optional
  *             'items' => array(
  *                 array(
  *                     'name' => 'ceiling',
  *                     'label' => 'Ceiling',            //optional
  *                     'type' => 'date',
  *                     'default' => date()              //optional
  *                 ),
  *                 array(
  *                     'name' => 'active_only',
  *                     'label' => 'ActiveOnly',
  *                     'type' => 'checkbox',
  *                     'default' => true
  *                 ),
  *                 array(
  *                     'name' => 'submit_button',
  *                     'type' => 'style_submit_button',
  *                     'value' => get_lang('Search'),
  *                     'attributes' => array('class' => 'search')
  *                 )
  *             )
  *         );
  *
  * @param array $form_data
  *
  * @return FormValidator
  */
 public static function create($form_data)
 {
     if (empty($form_data)) {
         return null;
     }
     $form_name = isset($form_data['name']) ? $form_data['name'] : 'form';
     $form_method = isset($form_data['method']) ? $form_data['method'] : 'POST';
     $form_action = isset($form_data['action']) ? $form_data['action'] : '';
     $form_target = isset($form_data['target']) ? $form_data['target'] : '';
     $form_attributes = isset($form_data['attributes']) ? $form_data['attributes'] : null;
     $form_track_submit = isset($form_data['track_submit']) ? $form_data['track_submit'] : true;
     $result = new FormValidator($form_name, $form_method, $form_action, $form_target, $form_attributes, $form_track_submit);
     $defaults = array();
     foreach ($form_data['items'] as $item) {
         $name = $item['name'];
         $type = isset($item['type']) ? $item['type'] : 'text';
         $label = isset($item['label']) ? $item['label'] : '';
         if ($type == 'wysiwyg') {
             $element = $result->add_html_editor($name, $label);
         } else {
             $element = $result->addElement($type, $name, $label);
         }
         if (isset($item['attributes'])) {
             $attributes = $item['attributes'];
             $element->setAttributes($attributes);
         }
         if (isset($item['value'])) {
             $value = $item['value'];
             $element->setValue($value);
         }
         if (isset($item['default'])) {
             $defaults[$name] = $item['default'];
         }
         if (isset($item['rules'])) {
             $rules = $item['rules'];
             foreach ($rules as $rule) {
                 $message = $rule['message'];
                 $type = $rule['type'];
                 $format = isset($rule['format']) ? $rule['format'] : null;
                 $validation = isset($rule['validation']) ? $rule['validation'] : 'server';
                 $force = isset($rule['force']) ? $rule['force'] : false;
                 $result->addRule($name, $message, $type, $format, $validation, $reset, $force);
             }
         }
     }
     $result->setDefaults($defaults);
     return $result;
 }
Example #13
0
            $actionsLeft .= $item;
        }
    }
    $actionsRight = '';
    if (count($a_sessions) > 0) {
        $actionsRight = Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick' => 'javascript: window.print();'));
        $actionsRight .= Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), 32), api_get_self() . '?export=csv');
    }
    $toolbar = Display::toolbarAction('toolbar-session', $content = array(0 => $actionsLeft, 1 => $actionsRight));
    echo $toolbar;
    echo Display::page_header(get_lang('YourSessionsList'));
} else {
    $a_sessions = Tracking::get_sessions_coached_by_user($id_coach);
}
$form = new FormValidator('search_course', 'get', api_get_path(WEB_CODE_PATH) . 'mySpace/session.php');
$form->addElement('text', 'keyword', get_lang('Keyword'));
$form->addButtonSearch(get_lang('Search'));
$keyword = '';
if ($form->validate()) {
    $keyword = $form->getSubmitValue('keyword');
}
$form->setDefaults(array('keyword' => $keyword));
$url = api_get_path(WEB_AJAX_PATH) . 'model.ajax.php?a=get_sessions_tracking&keyword=' . Security::remove_XSS($keyword);
$columns = array(get_lang('Title'), get_lang('Date'), get_lang('NbCoursesPerSession'), get_lang('NbStudentPerSession'), get_lang('Details'));
// Column config
$columnModel = array(array('name' => 'name', 'index' => 'name', 'width' => '255', 'align' => 'left'), array('name' => 'date', 'index' => 'date', 'width' => '150', 'align' => 'left', 'sortable' => 'false'), array('name' => 'course_per_session', 'index' => 'course_per_session', 'width' => '150', 'sortable' => 'false'), array('name' => 'student_per_session', 'index' => 'student_per_session', 'width' => '100', 'sortable' => 'false'), array('name' => 'details', 'index' => 'details', 'width' => '100', 'sortable' => 'false'));
$extraParams = array('autowidth' => 'true', 'height' => 'auto');
$js = '<script>
    $(function() {
        ' . Display::grid_js('session_tracking', $url, $columns, $columnModel, $extraParams, array(), null, true) . '
    });
        }
    }
    if ($total_resource_weight != $total_weight) {
        Display::display_warning_message(get_lang('SumOfActivitiesWeightMustBeEqualToTotalWeight'));
    }
}
$filter = api_get_setting('certificate_filter_by_official_code');
$userList = array();
$filterForm = null;
$certificate_list = array();
if ($filter === 'true') {
    echo '<br />';
    $options = UserManager::getOfficialCodeGrouped();
    $options = array_merge(array('all' => get_lang('All')), $options);
    $form = new FormValidator('official_code_filter', 'POST', api_get_self() . '?' . api_get_cidreq() . '&cat_id=' . $cat_id);
    $form->addElement('select', 'filter', get_lang('OfficialCode'), $options);
    $form->addButton('submit', get_lang('Submit'));
    $filterForm = '<br />' . $form->return_form();
    if ($form->validate()) {
        $officialCode = $form->getSubmitValue('filter');
        if ($officialCode == 'all') {
            $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
        } else {
            $userList = UserManager::getUsersByOfficialCode($officialCode);
            if (!empty($userList)) {
                $certificate_list = GradebookUtils::get_list_users_certificates($cat_id, $userList);
            }
        }
    } else {
        $certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
    }
Example #15
0
    $extraContentForm = new FormValidator('block_extra_data', 'post', '#', null, array('id' => 'block-extra-data', 'class' => ''), FormValidator::LAYOUT_BOX_NO_LABEL);
    $extraContentFormRenderer = $extraContentForm->getDefaultRenderer();
    if ($extraContentForm->validate()) {
        $extraData = $extraContentForm->getSubmitValues();
        $extraData = array_map(['Security', 'remove_XSS'], $extraData);
        if (!empty($extraData['block'])) {
            if (!is_dir($adminExtraContentDir)) {
                mkdir($adminExtraContentDir, api_get_permissions_for_new_directories(), true);
            }
            if (!is_writable($adminExtraContentDir)) {
                die;
            }
            $fullFilePath = $adminExtraContentDir . $extraData['block'];
            $fullFilePath .= "_extra.html";
            file_put_contents($fullFilePath, $extraData['extra_content']);
            Header::location(api_get_self());
        }
    }
    $extraContentForm->addTextarea('extra_content', null, ['id' => 'extra_content']);
    $extraContentFormRenderer->setElementTemplate('<div class="form-group">{element}</div>', 'extra_content');
    $extraContentForm->addElement('hidden', 'block', null, array('id' => 'extra-block'));
    $extraContentForm->addButtonExport(get_lang('Save'), 'submit_extra_content');
    $tpl->assign('extraDataForm', $extraContentForm->returnForm());
}
// The template contains the call to the AJAX version checker
$admin_template = $tpl->get_template('admin/settings_index.tpl');
$content = $tpl->fetch($admin_template);
$tpl->assign('content', $content);
$tpl->assign('message', $message);
$tpl->display_one_col_template();
// Note: version checking mechanism has now been moved to main/inc/ajax/admin.ajax.php
Example #16
0
 /**
  * Returns the form to update or create a document
  *
  * @param	string	Action (add/edit)
  * @param	integer	ID of the lp_item (if already exists)
  * @param	mixed	Integer if document ID, string if info ('new')
  * @return	string	HTML form
  */
 function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
 {
     global $charset, $_course;
     require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
     require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $path_parts = pathinfo($extra_info['dir']);
     $no_display_edit_textarea = false;
     //If action==edit document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "edit") {
         if (is_array($extra_info)) {
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_edit_textarea = true;
             }
         }
     }
     $no_display_add = false;
     //If action==add an existing document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "add") {
         if (is_numeric($extra_info)) {
             $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database::escape_string($extra_info);
             $result = Database::query($sql_doc, __FILE__, __LINE__);
             $path_file = Database::result($result, 0, 0);
             $path_parts = pathinfo($path_file);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_add = true;
             }
         }
     }
     // create css folder
     $css_name = api_get_setting('stylesheets');
     $perm = api_get_setting('permissions_for_new_directories');
     $perm = octdec(!empty($perm) ? $perm : '0770');
     $css_folder = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/css';
     if (!is_dir($css_folder)) {
         mkdir($css_folder);
         chmod($css_folder, $perm);
         $doc_id = add_document($_course, '/css', 'folder', 0, 'css');
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
     }
     if (!file_exists($css_folder . '/templates.css')) {
         if (file_exists(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css')) {
             $template_content = str_replace('../../img/', api_get_path(REL_CODE_PATH) . 'img/', file_get_contents(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css'));
             $template_content = str_replace('images/', api_get_path(REL_CODE_PATH) . 'css/' . $css_name . '/images/', $template_content);
             file_put_contents($css_folder . '/templates.css', $template_content);
         }
     }
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $table_sys_template = Database::get_main_table(TABLE_MAIN_SYSTEM_TEMPLATE);
         $user_id = api_get_user_id();
         // Session used by the ajax request when we are using php 5.3
         $_SESSION['dbName'] = $_course['dbName'];
         // setting some paths
         $img_dir = api_get_path(REL_CODE_PATH) . 'img/';
         $default_course_dir = api_get_path(REL_CODE_PATH) . 'default_course_document/';
         if (!isset($_GET['resource'])) {
             // Load a template into a document
             $query = 'SELECT content, title FROM ' . $table_sys_template . ' WHERE id=' . Database::escape_string(Security::remove_XSS($_GET['tplid']));
             $result = Database::query($query, __FILE__, __LINE__);
             $obj = Database::fetch_object($result);
             $valcontent = $obj->content;
             $valtitle = $obj->title != '' ? get_lang($obj->title) : get_lang('Empty');
             if (isset($_GET['tplid']) && $_GET['tplid'] == 0) {
                 $valcontent = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body></body>';
             }
             $template_css = '';
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $template_css = '<link rel="stylesheet" href="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/css/templates.css" type="text/css" />';
             }
             $js = '';
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'jwplayer/jwplayer.js" language="javascript"></script>' . PHP_EOL;
                 if (api_get_setting('show_glossary_in_documents') != 'none') {
                     $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.highlight.js"></script>';
                     if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>';
                     } else {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>';
                     }
                 }
             }
             $valcontent = str_replace('{CSS}', $template_css . $js, $valcontent);
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $valcontent = str_replace('</head>', $template_css . '</head>', $valcontent);
             }
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $valcontent = str_replace('</head>', $js . '</head>', $valcontent);
             }
             $valcontent = str_replace('{IMG_DIR}', $img_dir, $valcontent);
             $valcontent = str_replace('{REL_PATH}', api_get_path(REL_PATH), $valcontent);
             $valcontent = str_replace('{COURSE_DIR}', $default_course_dir, $valcontent);
         } elseif (isset($_GET['resource']) && $_GET['resource'] == 'mindmap' || $_GET['resource'] == 'video') {
             // Load a mindmap or video into a document
             $propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
             $curdirpath = '/mindmaps/';
             if ($_GET['resource'] == 'video') {
                 $curdirpath = '/video/';
                 $curdirpath_flv = '/video/flv/';
             }
             $my_course = api_get_course_id();
             $src_path = api_get_path(WEB_COURSE_PATH) . $my_course . '/document';
             $sql = "SELECT path,title FROM {$tbl_doc} doc,{$propTable} prop WHERE doc.id = prop.ref AND prop.tool = '" . TOOL_DOCUMENT . "'\n      AND doc.filetype = 'file' AND (doc.path LIKE '" . $curdirpath . "%' OR doc.path LIKE '" . $curdirpath_flv . "%') AND (doc.path NOT LIKE '" . $curdirpath . "%/%' OR doc.path NOT LIKE '" . $curdirpath_flv . "%/%')\n      AND prop.visibility = 1 AND doc.id = '" . Database::escape_string(Security::remove_XSS($_GET['tplid'])) . "'";
             $rs = Database::query($sql);
             $row = Database::fetch_array($rs);
             $resource = $src_path . $row['path'];
             $valtitle = $row['title'];
             if ($valtitle != '') {
                 $search = array('.png', '.gif', '.jpg', '.mpg', '.flv', '.swf');
                 // Add other extensions
                 $replace = array('', '', '', '', '', '');
                 $valtitle = str_replace($search, $replace, $valtitle);
             }
             if ($_GET['resource'] == 'mindmap') {
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
           <tbody>
               <tr>
                   <td valign="top"><img border="0" vspace="0" hspace="0" src="' . $resource . '" alt="' . $title . '" title="' . $title . '"/></td>
               </tr>
           </tbody>
       </table>';
             } elseif ($_GET['resource'] == 'video') {
                 $sys_resource = api_get_path(SYS_COURSE_PATH) . $my_course . '/document' . $row['path'];
                 $resource_info = pathinfo($sys_resource);
                 //$video_web_path = api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/flvPlayer/';
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
                                   <tbody>
                                       <tr>
                                          <td valign="top">                     
                                          <!-- Video player plugin -->
                                             <div id="player986311-parent" align="left">
                                             <div style="border-style: none; height: 240px; width: 375px; overflow: hidden; background-color: rgb(220, 220, 220);" id="test">
                                             <div style="display: none; visibility: hidden; width: 0px; height: 0px; overflow: hidden;" id="player986311-config">url=' . $resource . ' width=375 height=240 loop=1 play=true downloadable=false fullscreen=true</div>
                                                 <div class="thePlayer" id="player986311">';
                 if (in_array($resource_info['extension'], array('flv', 'mp4', 'mov'))) {
                     /*if (!api_is_windows_os()) {
                           $valcontent .= '   <script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                                               <object id="player986311-parent2" name="player986311-parent2" width="375" height="240" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
                                               <param name="movie" value="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf" />
                                               <param name="allowFullScreen" value="true" />
                                               <param name="allowscriptaccess" value="always" />
                                               <param name="seamlesstabbing" value="true" />
                                               <param name="wmode" value="transparent" />
                                               <param name="flashvars" value="id=player986311-parent2&autostart=true&repeat=false&file='.$resource.'&skin='.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip&controlbar.position=over"  />                
                                               </object>
                                          ';                                                          
                       } else {*/
                     $valcontent .= '           
                             <script src="' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                             <div id="player986311-parent2">Loading the player ...</div>
                             <script type="text/javascript">jwplayer("player986311-parent2").setup({flashplayer: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf",autostart: "true",repeat: "always",file: "' . $resource . '",height: 240,width: 375,skin: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip"});</script>';
                     //}
                 } else {
                     $sType = '';
                     if ($resource_info['extension'] == 'mpg' || $resource_info['extension'] == 'mpeg') {
                         $sType = 'video/mpeg';
                     } else {
                         if ($resource_info['extension'] == 'avi' || $resource_info['extension'] == 'wmv' || $resource_info['extension'] == 'asf') {
                             $sType = 'video/x-msvideo';
                         }
                     }
                     $valcontent .= '<embed type="' . $sType . '" src="' . $resource . '"
                            autosize = "false"
                            autostart = "true"
                            loop = "false"
                            fullscreen = "true"
                            showcontrols = "true"
                            showpositioncontrols = "false"
                            showtracker = "true"
                            showaudiocontrols = "true"
                            showgotobar = "true"
                            showstatusbar = "true"
                            pluginspace = "http://www.microsoft.com/Windows/MediaPlayer/"
                            codebase = "http://www.microsoft.com/Windows/MediaPlayer/"';
                     $valcontent .= 'width="375px" height="240px"';
                     $valcontent .= '></embed>';
                 }
                 $valcontent .= '              </div>
                                              </div>
                                           </div> 
                                         </td>
                                       </tr>
                                   </tbody>
                               </table>';
             }
         }
     }
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
         $item_terms = stripslashes($extra_info['terms']);
         if (empty($item_title)) {
             $path_parts = pathinfo($extra_info['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } elseif (is_numeric($extra_info)) {
         $sql_doc = "SELECT path, title\n\t\t\t\t\t\t\t\t\tFROM " . $tbl_doc . "\n\t\t\t\t\t\t\t\t\tWHERE id = " . Database::escape_string($extra_info);
         $result = Database::query($sql_doc, __FILE__, __LINE__);
         $row = Database::fetch_array($result);
         $explode = explode('.', $row['title']);
         if (count($explode) > 1) {
             for ($i = 0; $i < count($explode) - 1; $i++) {
                 $item_title .= $explode[$i];
             }
         } else {
             $item_title = $row['title'];
         }
         $item_title = str_replace('_', ' ', $item_title);
         if (empty($item_title)) {
             $path_parts = pathinfo($row['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } else {
         $item_title = '';
         $item_description = '';
     }
     /* $return = '	<div class="row">
        <div class="form_header">'; */
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $sql = "\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM " . $tbl_lp_item . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tlp_id = " . $this->lp_id;
     $result = Database::query($sql, __FILE__, __LINE__);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']);
     }
     $this->tree_array($arrLP);
     $arrLP = $this->arrMenu;
     unset($this->arrMenu);
     if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
         $return .= Display::return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
     }
     require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
     $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
     $defaults["title"] = Security::remove_XSS(api_convert_encoding($item_title, api_get_system_encoding(), $this->encoding));
     if (empty($item_title)) {
         $defaults["title"] = Security::remove_XSS($item_title);
     }
     $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
     $form->addElement('html', $return);
     if ($action != 'move') {
         $form->addElement('html', '<div style="float:left;padding-right:135px;">');
         $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
         $form->applyFilter('title', 'html_filter');
         $form->addElement('html', '</div>');
     }
     //$arrHide = array($id);
     $arrHide[0]['value'] = $this->name;
     $arrHide[0]['padding'] = 3;
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($action != 'add') {
             if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         }
     }
     //$parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
     $parent_select =& $form->addElement('select', 'parent', '', '', 'class="learnpath_item_form" style="width:40%;display:none;float:left" onchange="load_cbo(this.value);"');
     $my_count = 0;
     foreach ($arrHide as $key => $value) {
         if ($my_count != 0) {
             // the LP name is also the first section and is not in the same charset like the other sections
             $value['value'] = Security::remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         } else {
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         $my_count++;
     }
     if (!empty($id)) {
         $parent_select->setSelected($parent);
     } else {
         $parent_item_id = $_SESSION['parent_item_id'];
         $parent_select->setSelected($parent_item_id);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     //POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
         }
     }
     //$position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
     $position =& $form->addElement('select', 'previous', '', '', 'id="idPosition" class="learnpath_item_form" style="width:40%;float:left;display:none;"');
     $position->addOption(get_lang("FirstPosition"), 0);
     foreach ($arrHide as $key => $value) {
         $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
     }
     $position->setSelected($s_selected_position);
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     if ($action != 'move') {
         $id_prerequisite = 0;
         if (is_array($arrLP)) {
             foreach ($arrLP as $key => $value) {
                 if ($value['id'] == $id) {
                     $id_prerequisite = $value['prerequisite'];
                     break;
                 }
             }
         }
         //comented the prerequisites, only visible in edit (new document)
         //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
         //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
         // form element for uploading an mp3 file
         //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
         //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
         /* Code deprecated - moved to lp level (not lp-item)
             if ( api_get_setting('search_enabled') === 'true' )
             {
             //add terms field
             $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
             $terms->setValue($item_terms);
             }
            */
         $arrHide = array();
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
                 if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = $arrLP[$i]['id'];
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
             }
         }
         /* 	foreach($arrHide as $key => $value){
              $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
              if($key==$s_selected_position && $action == 'add'){
              $select_prerequisites -> setSelected(0);
              }
              elseif($key==$id_prerequisite && $action == 'edit'){
              $select_prerequisites -> setSelected($id_prerequisite);
              }
              }
             */
         if (!$no_display_add) {
             if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
                 if (isset($_POST['content'])) {
                     $content = stripslashes($_POST['content']);
                 } elseif (is_array($extra_info)) {
                     //If it's an html document or a text file
                     if (!$no_display_edit_textarea) {
                         $content = $this->display_document($extra_info['path'], false, false);
                     }
                 } elseif (is_numeric($extra_info)) {
                     $content = $this->display_document($extra_info, false, false);
                 } else {
                     $content = '';
                 }
                 if (!$no_display_edit_textarea) {
                     // We need to claculate here some specific settings for the online editor.
                     // The calculated settings work for documents in the Documents tool
                     // (on the root or in subfolders).
                     // For documents in native scorm packages it is unclear whether the
                     // online editor should be activated or not.
                     $relative_path = $extra_info['dir'];
                     if ($relative_path == 'n/') {
                         // A new document, it is in the root of the repository.
                         $relative_path = '';
                         $relative_prefix = '';
                     } else {
                         // The document already exists. Whe have to determine its relative path towards the repository root.
                         $relative_path = explode('/', $relative_path);
                         $cnt = count($relative_path) - 2;
                         if ($cnt < 0) {
                             $cnt = 0;
                         }
                         $relative_prefix = str_repeat('../', $cnt);
                         $relative_path = array_slice($relative_path, 1, $cnt);
                         $relative_path = implode('/', $relative_path);
                         if (strlen($relative_path) > 0) {
                             $relative_path = $relative_path . '/';
                         }
                     }
                     $editor_config = array('ToolbarSet' => api_is_allowed_to_edit() ? 'Documents' : 'DocumentsStudent', 'Width' => '100%', 'Height' => '700', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/', 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path);
                     if ($_GET['action'] == 'add_item') {
                         $class = 'save';
                         $text = get_lang('Validate');
                     } else {
                         if ($_GET['action'] == 'edit_item') {
                             $class = 'save';
                             $text = get_lang('SaveDocument');
                         }
                     }
                     $form->addElement('html', '<div style="float:right;margin-top:-55px">');
                     $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
                     $form->addElement('html', '</div>');
                     $renderer = $form->defaultRenderer();
                     $renderer->setElementTemplate('{label}{element}', 'content_lp');
                     //$form->addElement('html', '<div');
                     $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
                     //$form->addElement('html', '</div>');
                     $defaults["content_lp"] = $content;
                 }
             } elseif (is_numeric($extra_info)) {
                 $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
                 $return = $this->display_document($extra_info, true, true, true);
                 $form->addElement('html', $return);
             }
         }
     }
     // Add template to content
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $defaults["content_lp"] = $valcontent;
         $defaults["title"] = $valtitle;
     }
     if ($action == 'move') {
         $form->addElement('hidden', 'title', $item_title);
         $form->addElement('hidden', 'description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save" style="float:right"');
         $form->addElement('hidden', 'path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addElement('html', '<div style="float:right;margin-top:-55px">');
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
         $form->addElement('hidden', 'path', $extra_info['path']);
         $form->addElement('html', '</div>');
     }
     $form->addElement('hidden', 'type', TOOL_DOCUMENT);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
Example #17
0
  if (num_characters > num_characters_permited){
      document.forms[0].description.value = textarea;
   }else{
      textarea = document.forms[0].description.value;
   }
}
</script>';
// Database table definitions
if (!empty($_GET['message'])) {
    $message = urldecode($_GET['message']);
}
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$tool_name = get_lang('AddGroups');
// Create the form
$form = new FormValidator('group_add');
$form->addElement('header', $tool_name);
// name
$form->addElement('text', 'name', get_lang('Name'), array('size' => 60, 'maxlength' => 120));
$form->applyFilter('name', 'html_filter');
$form->applyFilter('name', 'trim');
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
// Description
$form->addElement('textarea', 'description', get_lang('Description'), array('rows' => 3, 'cols' => 58, 'onKeyDown' => "text_longitud()", 'onKeyUp' => "text_longitud()"));
$form->applyFilter('description', 'html_filter');
$form->applyFilter('description', 'trim');
// url
$form->addElement('text', 'url', get_lang('URL'), array('size' => 35));
$form->applyFilter('url', 'html_filter');
$form->applyFilter('url', 'trim');
// Picture
$form->addElement('file', 'picture', get_lang('AddPicture'));
                        var includeAllUsers  = $("input[name=include_all_users]:checked").val();
                        var attempts = $("input[name=only_best_attempts]:checked").val();

                        location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data+"&include_all_users="+includeAllUsers+"&only_best_attempts="+attempts;
                        $( this ).dialog( "close" );
                    }
                }
            });
            $( "#dialog-confirm" ).dialog("open");
            return false;
        });
    });
    </script>';
$extra .= '<div id="dialog-confirm" title="' . get_lang("ConfirmYourChoice") . '">';
$form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
$form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label'));
$form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
$form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
$form->addElement('checkbox', 'include_all_users', null, get_lang('IncludeAllUsers'), '0');
$form->addElement('checkbox', 'only_best_attempts', null, get_lang('OnlyBestAttempts'), '0');
$form->setDefaults(array('export_format' => 'csv'));
$extra .= $form->return_form();
$extra .= '</div>';
if ($is_allowedToEdit) {
    echo $extra;
}
echo $actions;
$url = api_get_path(WEB_AJAX_PATH) . 'model.ajax.php?a=get_exercise_results&exerciseId=' . $exercise_id . '&filter_by_user='******'&' . api_get_cidreq();
$action_links = '';
//Generating group list
$group_list = GroupManager::get_group_list();
 *
 * @package chamilo.learnpath
 */
$this_section = SECTION_COURSES;
api_protect_course_script();
require 'learnpath_functions.inc.php';
require 'resourcelinker.inc.php';
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
if (!$is_allowed_to_edit) {
    header('location:lp_controller.php?action=list&' . api_get_cidreq());
    exit;
}
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list?' . api_get_cidreq(), 'name' => get_lang('LearningPaths'));
$form = new FormValidator('lp_add_category', 'post', 'lp_controller.php?' . api_get_cidreq());
// Form title
$form->addElement('header', null, get_lang('AddLPCategory'));
// Title
$form->addElement('text', 'name', api_ucfirst(get_lang('Name')));
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'action', 'add_lp_category');
$form->addElement('hidden', 'c_id', api_get_course_int_id());
$form->addElement('hidden', 'id', 0);
$form->addButtonSave(get_lang('Save'));
if ($form->validate()) {
    $values = $form->getSubmitValues();
    if (!empty($values['id'])) {
        learnpath::updateCategory($values);
        $url = api_get_self() . '?action=list&' . api_get_cidreq();
        header('Location: ' . $url);
        exit;
    } else {
Example #20
0
function manage_form($default, $select_from_user_list = null, $sent_to = null)
{
    $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
    $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null;
    $param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null;
    $form = new FormValidator('compose_message', null, api_get_self() . '?f=' . $param_f, null, array('enctype' => 'multipart/form-data'));
    if (empty($group_id)) {
        if (isset($select_from_user_list)) {
            $form->addText('id_text_name', get_lang('SendMessageTo'), true, array('id' => 'id_text_name', 'onkeyup' => 'send_request_and_search()', 'autocomplete' => 'off'));
            $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required');
            $form->addElement('html', '<div id="id_div_search" style="padding:0px" class="message-select-box" >&nbsp;</div>');
            $form->addElement('hidden', 'user_list', 0, array('id' => 'user_list'));
        } else {
            if (!empty($sent_to)) {
                $form->addLabel(get_lang('SendMessageTo'), $sent_to);
            }
            if (empty($default['users'])) {
                //fb select
                $form->addElement('select_ajax', 'users', get_lang('SendMessageTo'), array(), ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH) . 'message.ajax.php?a=find_users']);
            } else {
                $form->addElement('hidden', 'hidden_user', $default['users'][0], array('id' => 'hidden_user'));
            }
        }
    } else {
        $userGroup = new UserGroup();
        $group_info = $userGroup->get($group_id);
        $form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name']));
        $form->addElement('hidden', 'group_id', $group_id);
        $form->addElement('hidden', 'parent_id', $message_id);
    }
    $form->addText('title', get_lang('Subject'), true);
    $form->addHtmlEditor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250'));
    if (isset($_GET['re_id'])) {
        $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']);
        $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_reply_info['title'];
        $form->addElement('hidden', 're_id', intval($_GET['re_id']));
        $form->addElement('hidden', 'save_form', 'save_form');
        //adding reply mail
        $user_reply_info = api_get_user_info($message_reply_info['user_sender_id']);
        $default['content'] = '<p><br/></p>' . sprintf(get_lang('XWroteY'), $user_reply_info['complete_name'], Security::filter_terms($message_reply_info['content']));
    }
    if (empty($group_id)) {
        $form->addElement('label', '', '<div  id="filepaths" class="form-group">
                    <div id="filepath_1">
                    <label>' . get_lang('FilesAttachment') . '</label>
                    <input type="file" name="attach_1"/>
                    <label>' . get_lang('Description') . '</label>
                    <input id="file-descrtiption" type="text" name="legend[]" class="form-control"/>
                    </div>
                </div>');
        $form->addElement('label', '', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</a></span>&nbsp;(' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message.message_max_upload_filesize'))) . ')');
    }
    $form->addButtonSend(get_lang('SendMessage'), 'compose');
    $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
    if (!empty($group_id) && !empty($message_id)) {
        $message_info = MessageManager::get_message_by_id($message_id);
        $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_info['title'];
    }
    $form->setDefaults($default);
    $html = '';
    if ($form->validate()) {
        $check = Security::check_token('post');
        if ($check) {
            $user_list = $default['users'];
            $file_comments = $_POST['legend'];
            $title = $default['title'];
            $content = $default['content'];
            $group_id = isset($default['group_id']) ? $default['group_id'] : null;
            $parent_id = isset($default['parent_id']) ? $default['parent_id'] : null;
            if (is_array($user_list) && count($user_list) > 0) {
                //all is well, send the message
                foreach ($user_list as $user) {
                    $res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id);
                    if ($res) {
                        $html .= MessageManager::display_success_message($user);
                    }
                }
            } else {
                Display::display_error_message('ErrorSendingMessage');
            }
        }
        Security::clear_token();
    } else {
        $token = Security::get_token();
        $form->addElement('hidden', 'sec_token');
        $form->setConstants(array('sec_token' => $token));
        $html .= $form->returnForm();
    }
    return $html;
}
/* Header */
$tool_name = get_lang('AddUsersToACourse');
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$htmlHeadXtra[] = '
<script type="text/javascript">
function validate_filter() {
        document.formulaire.form_sent.value=0;
        document.formulaire.submit();
}
</script>';
// displaying the header
Display::display_header($tool_name);
$link_add_group = '<a href="usergroups.php">' . Display::return_icon('multiple.gif', get_lang('RegistrationByUsersGroups')) . get_lang('RegistrationByUsersGroups') . '</a>';
echo '<div class="actions">' . $link_add_group . '</div>';
$form = new FormValidator('subscribe_user2course');
$form->addElement('header', '', $tool_name);
$form->display();
//checking for extra field with filter on
$extra_field_list = UserManager::get_extra_fields();
$new_field_list = array();
if (is_array($extra_field_list)) {
    foreach ($extra_field_list as $extra_field) {
        //if is enabled to filter and is a "<select>" field type
        if ($extra_field[8] == 1 && $extra_field[2] == 4) {
            $new_field_list[] = array('name' => $extra_field[3], 'variable' => $extra_field[1], 'data' => $extra_field[9]);
        }
    }
}
/* React on POSTed request */
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
    $form_sent = $_POST['form_sent'];
Example #22
0
    /**
     * Creates the form to create / edit a question
     * A subclass can redifine this function to add fields...
     *
     * @param \FormValidator $form the formvalidator instance (by reference)
     * @param array $fck_config
     */
    public function createForm(&$form, $fck_config = array())
    {
        $maxCategories = 1;
        $url = api_get_path(WEB_AJAX_PATH) . 'exercise.ajax.php?1=1';
        $js = null;
        if ($this->type != MEDIA_QUESTION) {
            $js = '<script>

            function check() {
                var counter = 0;
                $("#category_id option:selected").each(function() {
                    var id = $(this).val();
                    var name = $(this).text();
                    if (id != "" ) {
                        // if a media question was selected
                        $("#parent_id option:selected").each(function() {
                            var questionId = $(this).val();
                            if (questionId != 0) {
                                if (counter >= 1) {
                                    alert("' . addslashes(get_lang('YouCantAddAnotherCategory')) . '");
                                    $("#category_id").trigger("removeItem",[{ "value" : id}]);
                                    return;
                                }
                            }
                        });

                        $.ajax({
                            async: false,
                            url: "' . $url . '&a=exercise_category_exists",
                            data: "id="+id,
                            success: function(return_value) {
                                if (return_value == 0 ) {
                                    alert("' . addslashes(get_lang('CategoryDoesNotExists')) . '");
                                    // Deleting select option tag
                                    $("#category_id").find("option").remove();

                                    $(".holder li").each(function () {
                                        if ($(this).attr("rel") == id) {
                                            $(this).remove();
                                        }
                                    });
                                }
                            },
                        });
                    }
                    counter++;
                });
            }

            $(function() {
                $("#category_id").fcbkcomplete({
                    json_url: "' . $url . '&a=search_category_parent&type=all&filter_by_global=' . $this->exercise->getGlobalCategoryId() . '",
                    maxitems: "' . $maxCategories . '",
                    addontab: false,
                    input_min_size: 1,
                    cache: false,
                    complete_text:"' . get_lang('StartToType') . '",
                    firstselected: false,
                    onselect: check,
                    filter_selected: true,
                    newel: true
                });

                // Change select media
                $("#parent_id").change(function(){
                    $("#parent_id option:selected").each(function() {
                        var questionId = $(this).val();
                        if (questionId != 0) {
                            $.ajax({
                                async: false,
                                dataType: "json",
                                url: "' . $url . '&a=get_categories_by_media&questionId=' . $this->id . '&exerciseId=' . $this->exercise->id . '",
                                data: "mediaId="+questionId,
                                success: function(data) {
                                    if (data != -1) {
                                        var all = $("#category_id").trigger("selectAll");
                                        all.each(function(index, value) {
                                            var selected = $(value).find("option:selected");
                                            selected.each(function( indexSelect, valueSelect) {
                                                valueToRemove = $(valueSelect).val();
                                                $("#category_id").trigger("removeItem",[{ "value" : valueToRemove}]);
                                            });
                                        });

                                        if (data != 0) {
                                            $("#category_id").trigger("addItem",[{"title": data.title, "value": data.value}]);
                                        }
                                    }
                                },
                            });
                        } else {

                            // Removes all items
                            var all = $("#category_id").trigger("selectAll");
                            all.each(function(index, value) {
                                var selected = $(value).find("option:selected");
                                selected.each(function( indexSelect, valueSelect) {
                                    valueToRemove = $(valueSelect).val();
                                    $("#category_id").trigger("removeItem", [{ "value" : valueToRemove}]);
                                });
                            });
                        }
                    });
                });
            });

            // hub 13-12-2010
            function visiblerDevisibler(in_id) {
                if (document.getElementById(in_id)) {

                    if (document.getElementById(in_id).style.display == "none") {
                        document.getElementById(in_id).style.display = "block";
                        if (document.getElementById(in_id+"Img")) {
                            document.getElementById(in_id+"Img").html = "' . addslashes(Display::return_icon('div_hide.gif')) . '";
                        }
                    } else {
                        document.getElementById(in_id).style.display = "none";
                        if (document.getElementById(in_id+"Img")) {
                            document.getElementById(in_id+"Img").html = "dsdsds' . addslashes(Display::return_icon('div_show.gif')) . '";
                        }
                    }
                }
            }
            </script>';
            $form->addElement('html', $js);
        }
        // question name
        $form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6'));
        $form->addRule('questionName', get_lang('GiveQuestion'), 'required');
        // Default content.
        $isContent = isset($_REQUEST['isContent']) ? intval($_REQUEST['isContent']) : null;
        // Question type
        $answerType = isset($_REQUEST['answerType']) ? intval($_REQUEST['answerType']) : $this->selectType();
        $form->addElement('hidden', 'answerType', $answerType);
        // html editor
        $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150');
        if (is_array($fck_config)) {
            $editor_config = array_merge($editor_config, $fck_config);
        }
        if (!api_is_allowed_to_edit(null, true)) {
            $editor_config['UserStatus'] = 'student';
        }
        $form->add_html_editor('questionDescription', get_lang('QuestionDescription'), false, false, $editor_config);
        // hidden values
        $my_id = isset($_REQUEST['myid']) ? intval($_REQUEST['myid']) : null;
        $form->addElement('hidden', 'myid', $my_id);
        if ($this->type != MEDIA_QUESTION) {
            if ($this->exercise->fastEdition == false) {
                // Advanced parameters
                $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
                $form->addElement('html', '<div id="advanced_params_options" style="display:none;">');
            }
            // Level (difficulty).
            $select_level = Question::get_default_levels();
            $form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level);
            // Media question.
            $course_medias = Question::prepare_course_media_select(api_get_course_int_id());
            $form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias, array('id' => 'parent_id'));
            // Categories.
            $categoryJS = null;
            if (!empty($this->category_list)) {
                $trigger = '';
                foreach ($this->category_list as $category_id) {
                    if (!empty($category_id)) {
                        $cat = new Testcategory($category_id);
                        if ($cat->id) {
                            $trigger .= '$("#category_id").trigger("addItem",[{"title": "' . $cat->parent_path . '", "value": "' . $cat->id . '"}]);';
                        }
                    }
                }
                $categoryJS .= '<script>$(function() { ' . $trigger . ' });</script>';
            }
            $form->addElement('html', $categoryJS);
            $form->addElement('select', 'questionCategory', get_lang('Category'), array(), array('id' => 'category_id'));
            // Extra fields. (Injecting question extra fields!)
            $extraFields = new ExtraField('question');
            $extraFields->addElements($form, $this->id);
            if ($this->exercise->fastEdition == false) {
                $form->addElement('html', '</div>');
            }
        }
        // @todo why we need this condition??
        if ($this->setDefaultQuestionValues) {
            switch ($answerType) {
                case 1:
                    $this->question = get_lang('DefaultUniqueQuestion');
                    break;
                case 2:
                    $this->question = get_lang('DefaultMultipleQuestion');
                    break;
                case 3:
                    $this->question = get_lang('DefaultFillBlankQuestion');
                    break;
                case 4:
                    $this->question = get_lang('DefaultMathingQuestion');
                    break;
                case 5:
                    $this->question = get_lang('DefaultOpenQuestion');
                    break;
                case 9:
                    $this->question = get_lang('DefaultMultipleQuestion');
                    break;
            }
        }
        // default values
        $defaults = array();
        $defaults['questionName'] = $this->question;
        $defaults['questionDescription'] = $this->description;
        $defaults['questionLevel'] = $this->level;
        $defaults['questionCategory'] = $this->category_list;
        $defaults['parent_id'] = $this->parent_id;
        if (!empty($_REQUEST['myid'])) {
            $form->setDefaults($defaults);
        } else {
            if ($isContent == 1) {
                $form->setDefaults($defaults);
            }
        }
        if ($this->setDefaultValues) {
            $form->setDefaults($defaults);
        }
    }
Example #23
0
}

function activate_end_date() {
    if(document.getElementById(\'end_date_div\').style.display == \'none\') {
        document.getElementById(\'end_date_div\').style.display = \'block\';
    } else {
        document.getElementById(\'end_date_div\').style.display = \'none\';
    }
}

</script>';
$gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null;
$defaults = array();
$form = new FormValidator('form1', 'post', 'lp_controller.php');
// Form title
$form->addElement('header', get_lang('EditLPSettings'));
// Title
$form->addElement('text', 'lp_name', api_ucfirst(get_lang('LearnpathTitle')), array('class' => 'span5'));
$form->applyFilter('lp_name', 'html_filter');
$form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'lp_encoding');
$referer = isset($_REQUEST['referer']) ? Security::remove_XSS($_REQUEST['referer']) : null;
$form->addElement('hidden', 'referer', $referer);
$items = learnpath::get_category_from_course_into_select(api_get_course_int_id(), true);
$form->addElement('select', 'category_id', get_lang('Category'), $items);
//Hide toc frame
$hide_toc_frame = $form->addElement('checkbox', 'hide_toc_frame', null, get_lang('HideTocFrame'), array('onclick' => '$("#lp_layout_column").toggle()'));
if (api_get_setting('allow_course_theme') == 'true') {
    $mycourselptheme = api_get_course_setting('allow_learning_path_theme');
    if (!empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
        //LP theme picker
Example #24
0
$tool_name = get_lang('GroupEdit');
$interbreadcrumb[] = array('url' => 'home.php', 'name' => get_lang('Social'));
$interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
$usergroup = new UserGroup();
$group_data = $usergroup->get($group_id);
if (empty($group_data)) {
    header('Location: groups.php?id=' . $group_id);
    exit;
}
//only group admins can edit the group
if (!$usergroup->is_group_admin($group_id)) {
    api_not_allowed();
}
// Create the form
$form = new FormValidator('group_edit', 'post', '', '');
$form->addElement('hidden', 'id', $group_id);
$usergroup->setGroupType($usergroup::SOCIAL_CLASS);
$usergroup->setForm($form, 'edit', $group_data);
// Set default values
$form->setDefaults($group_data);
// Validate form
if ($form->validate()) {
    $group = $form->exportValues();
    $group['id'] = $group_id;
    $group['type'] = $usergroup::SOCIAL_CLASS;
    $usergroup->update($group);
    $tok = Security::get_token();
    header('Location: groups.php?id=' . $group_id . '&action=show_message&message=' . urlencode(get_lang('GroupUpdated')) . '&sec_token=' . $tok);
    exit;
}
$social_left_content = SocialManager::show_social_menu('group_edit', $group_id);
    if (isset($value['max_student']) && isset($value['group_members']) && $value['max_student'] < count($value['group_members'])) {
        return array('group_members' => get_lang('GroupTooMuchMembers'));
    }
    return true;
}
/*	MAIN CODE */
$htmlHeadXtra[] = '<script>
$(document).ready( function() {
    $("#max_member").on("focus", function() {
        $("#max_member_selected").attr("checked", true);
    });
});
 </script>';
// Build form
$form = new FormValidator('group_edit', 'post', api_get_self() . '?' . api_get_cidreq());
$form->addElement('hidden', 'action');
$form->addElement('hidden', 'max_student', $current_group['max_student']);
$complete_user_list = GroupManager::fill_groups_list($current_group['id']);
$orderUserListByOfficialCode = api_get_setting('platform.order_user_list_by_official_code');
$possible_users = array();
$userGroup = new UserGroup();
if (!empty($complete_user_list)) {
    usort($complete_user_list, 'sort_users');
    foreach ($complete_user_list as $index => $user) {
        $officialCode = !empty($user['official_code']) ? ' - ' . $user['official_code'] : null;
        $groups = $userGroup->getUserGroupListByUser($user['user_id']);
        $groupNameListToString = '';
        if (!empty($groups)) {
            $groupNameList = array_column($groups, 'name');
            $groupNameListToString = ' - [' . implode(', ', $groupNameList) . ']';
        }
Example #26
0
    );
    $options = array (
        2 => '2 '.get_lang('Days'),
        3 => '3 '.get_lang('Days'),
        4 => '4 '.get_lang('Days'),
        5 => '5 '.get_lang('Days'),
        6 => '6 '.get_lang('Days'),
        7 => '7 '.get_lang('Days'),
        15 => '15 '.get_lang('Days'),
        30 => '30 '.get_lang('Days'),
        'never' => get_lang('Never')
    );

    $el = $form->addElement(
        'select',
        'since',
        '<img width="ICON_SIZE_SMALL" align="middle" src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" border="0" />'.get_lang('RemindInactivesLearnersSince'),
        $options
    );
    $el->setSelected(7);

    $form->addElement('hidden', 'action', 'add');
    $form->addElement('hidden', 'remindallinactives', 'true');

    $extra_field_select = TrackingCourseLog::display_additional_profile_fields();

    if (!empty($extra_field_select)) {
        echo $extra_field_select;
    }

    $form->display();
Example #27
0
if (!($is_allowed_to_edit || GroupManager::groupMemberWithUploadRights() || is_my_shared_folder($_user['user_id'], Security::remove_XSS($dir), api_get_session_id()))) {
    api_not_allowed(true);
}
Event::event_access_tool(TOOL_DOCUMENT);
$display_dir = $dir;
if (isset($group_properties)) {
    $display_dir = explode('/', $dir);
    unset($display_dir[0]);
    unset($display_dir[1]);
    $display_dir = implode('/', $display_dir);
}
$select_cat = isset($_GET['selectcat']) ? intval($_GET['selectcat']) : null;
// Create a new form
$form = new FormValidator('create_document', 'post', api_get_self() . '?' . api_get_cidreq() . '&dir=' . Security::remove_XSS(urlencode($dir)) . '&selectcat=' . $select_cat, null, array('class' => 'form-horizontal'));
// form title
$form->addElement('header', $nameTools);
if ($is_certificate_mode) {
    //added condition for certicate in gradebook
    $form->addElement('hidden', 'certificate', 'true', array('id' => 'certificate'));
    if (isset($_GET['selectcat'])) {
        $form->addElement('hidden', 'selectcat', $select_cat);
    }
}
// Hidden element with current directory
$form->addElement('hidden', 'id');
$defaults = array();
$defaults['id'] = $folder_id;
// Filename
$form->addElement('hidden', 'title_edited', 'false', 'id="title_edited"');
/**
 * Check if a document width the choosen filename allready exists
Example #28
0
api_protect_course_script(true);
// error messages
if ($error) {
    Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'), false);
}
$param_gradebook = '';
if (isset($_SESSION['gradebook'])) {
    $param_gradebook = '&gradebook=' . Security::remove_XSS($_SESSION['gradebook']);
}
if (!$error) {
    $token = Security::get_token();
}
$attendance_weight = floatval($attendance_weight);
// display form
$form = new FormValidator('attendance_edit', 'POST', 'index.php?action=attendance_edit&' . api_get_cidreq() . '&attendance_id=' . $attendance_id . $param_gradebook);
$form->addElement('header', '', get_lang('Edit'));
$form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'attendance_id', $attendance_id);
$form->add_textfield('title', get_lang('Title'), true, array('size' => '50'));
$form->applyFilter('title', 'html_filter');
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200'));
// Adavanced Parameters
if (Gradebook::is_active()) {
    if (!empty($attendance_qualify_title) || !empty($attendance_weight)) {
        $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
        $form->addElement('html', '<div id="id_qualify_options" style="display:block">');
        $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), array('checked' => 'true', 'onclick' => 'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}'));
        $form->addElement('html', '<div id="options_field" style="display:block">');
    } else {
        $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
        $form->addElement('html', '<div id="id_qualify_options" style="display:none">');
 /**
  * Shows statistics about the time of last visit to each course.
  */
 static function print_course_last_visit()
 {
     $access_url_rel_course_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
     $current_url_id = api_get_current_access_url_id();
     $columns[0] = 'c_id';
     $columns[1] = 'access_date';
     $sql_order[SORT_ASC] = 'ASC';
     $sql_order[SORT_DESC] = 'DESC';
     $per_page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 10;
     $page_nr = isset($_GET['page_nr']) ? intval($_GET['page_nr']) : 1;
     $column = isset($_GET['column']) ? intval($_GET['column']) : 0;
     $date_diff = isset($_GET['date_diff']) ? intval($_GET['date_diff']) : 60;
     if (!in_array($_GET['direction'], array(SORT_ASC, SORT_DESC))) {
         $direction = SORT_ASC;
     } else {
         $direction = isset($_GET['direction']) ? $_GET['direction'] : SORT_ASC;
     }
     $form = new FormValidator('courselastvisit', 'get');
     $form->addElement('hidden', 'report', 'courselastvisit');
     $form->add_textfield('date_diff', get_lang('Days'), true);
     $form->addRule('date_diff', 'InvalidNumber', 'numeric');
     $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
     if (!isset($_GET['date_diff'])) {
         $defaults['date_diff'] = 60;
     } else {
         $defaults['date_diff'] = Security::remove_XSS($_GET['date_diff']);
     }
     $form->setDefaults($defaults);
     $form->display();
     $values = $form->exportValues();
     $date_diff = $values['date_diff'];
     $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
     $tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
     if (api_is_multiple_url_enabled()) {
         $sql = "SELECT access_date, c.code FROM {$table} s , {$access_url_rel_course_table} u, {$tableCourse} c\n                    WHERE c.id = u.c_id AND c.id = s.c_id AND access_url_id='" . $current_url_id . "' " . "GROUP BY access_cours_code " . "HAVING s.c_id <> '' " . "AND DATEDIFF( '" . date('Y-m-d h:i:s') . "' , access_date ) <= " . $date_diff;
     } else {
         $sql = "SELECT access_date, c.code FROM {$table} , {$tableCourse} c\n                    WHERE c_id = c.id\n                    GROUP BY c_id\n                    HAVING c_id <> ''AND\n                    DATEDIFF( '" . date('Y-m-d h:i:s') . "' , access_date ) <= " . $date_diff;
     }
     $res = Database::query($sql);
     $number_of_courses = Database::num_rows($res);
     $sql .= ' ORDER BY ' . $columns[$column] . ' ' . $sql_order[$direction];
     $from = ($page_nr - 1) * $per_page;
     $sql .= ' LIMIT ' . $from . ',' . $per_page;
     echo '<p>' . get_lang('LastAccess') . ' &gt;= ' . $date_diff . ' ' . get_lang('Days') . '</p>';
     $res = Database::query($sql);
     if (Database::num_rows($res) > 0) {
         $courses = array();
         while ($obj = Database::fetch_object($res)) {
             $course = array();
             $course[] = '<a href="' . api_get_path(WEB_PATH) . 'courses/' . $obj->code . '">' . $obj->code . ' <a>';
             //Allow sort by date hiding the numerical date
             $course[] = '<span style="display:none;">' . $obj->access_date . '</span>' . api_convert_and_format_date($obj->access_date);
             $courses[] = $course;
         }
         $parameters['date_diff'] = $date_diff;
         $parameters['report'] = 'courselastvisit';
         $table_header[] = array(get_lang("CourseCode"), true);
         $table_header[] = array(get_lang("LastAccess"), true);
         Display::display_sortable_table($table_header, $courses, array('column' => $column, 'direction' => $direction), array(), $parameters);
     } else {
         echo get_lang('NoSearchResults');
     }
 }
Example #30
0
 /**
  * @param FormValidator $form
  * @param string        $type
  * @param array         $data
  */
 public function setForm($form, $type = 'add', $data = array())
 {
     switch ($type) {
         case 'add':
             $header = get_lang('Add');
             break;
         case 'edit':
             $header = get_lang('Edit');
             break;
     }
     $form->addElement('header', $header);
     //Name
     $form->addElement('text', 'name', get_lang('Name'), array('maxlength' => 255));
     $form->applyFilter('name', 'html_filter');
     $form->applyFilter('name', 'trim');
     $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     $form->addRule('name', '', 'maxlength', 255);
     // Description
     $form->addElement('textarea', 'description', get_lang('Description'), array('cols' => 58));
     $form->applyFilter('description', 'html_filter');
     $form->applyFilter('description', 'trim');
     if ($this->showGroupTypeSetting) {
         $form->addElement('checkbox', 'group_type', null, get_lang('SocialGroup'));
     }
     // url
     $form->addElement('text', 'url', get_lang('Url'));
     $form->applyFilter('url', 'html_filter');
     $form->applyFilter('url', 'trim');
     // Picture
     $allowed_picture_types = $this->getAllowedPictureExtensions();
     $form->addElement('file', 'picture', get_lang('AddPicture'));
     $form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
     if (isset($data['picture']) && strlen($data['picture']) > 0) {
         $picture = $this->get_picture_group($data['id'], $data['picture'], 80);
         $img = '<img src="' . $picture['file'] . '" />';
         $form->addElement('label', null, $img);
         $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
     }
     $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $this->getGroupStatusList());
     $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
     // Setting the form elements
     if ($type == 'add') {
         $form->addButtonCreate($header);
     } else {
         $form->addButtonUpdate($header);
     }
 }