protected function build_create() { $this->addElement('header', get_lang('MakeLink')); $select = $this->addElement('select', 'select_link', get_lang('ChooseLink'), null, array('onchange' => 'document.create_link.submit()')); $linktypes = LinkFactory::get_all_types(); $select->addoption('[' . get_lang('ChooseLink') . ']', 0); $cc = $this->category_object->get_course_code(); foreach ($linktypes as $linktype) { $link = LinkFactory::create($linktype); if (!empty($cc)) { $link->set_course_code($cc); } elseif (!empty($_GET['course_code'])) { $link->set_course_code(Database::escape_string($_GET['course_code'])); } // disable this element if the link works with a dropdownlist // and if there are no links left if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') { $select->addoption($link->get_type_name(), $linktype, 'disabled'); } else { $select->addoption($link->get_type_name(), $linktype); } } if (isset($this->extra)) { $this->setDefaults(array('select_link' => $this->extra)); } }
/** * Adds a resource to the unique gradebook of a given course * @param int * @param string Course code * @param int Resource type (use constants defined in linkfactory.class.php) * @param int Resource ID in the corresponding tool * @param string Resource name to show in the gradebook * @param int Resource weight to set in the gradebook * @param int Resource max * @param string Resource description * @param int Visibility (0 hidden, 1 shown) * @param int Session ID (optional or 0 if not defined) * @param int * @return boolean True on success, false on failure */ public static function add_resource_to_course_gradebook($category_id, $course_code, $resource_type, $resource_id, $resource_name = '', $weight = 0, $max = 0, $resource_description = '', $visible = 0, $session_id = 0, $link_id = null) { $link = LinkFactory::create($resource_type); $link->set_user_id(api_get_user_id()); $link->set_course_code($course_code); if (empty($category_id)) { return false; } $link->set_category_id($category_id); if ($link->needs_name_and_description()) { $link->set_name($resource_name); } else { $link->set_ref_id($resource_id); } $link->set_weight($weight); if ($link->needs_max()) { $link->set_max($max); } if ($link->needs_name_and_description()) { $link->set_description($resource_description); } $link->set_visible(empty($visible) ? 0 : 1); if (!empty($session_id)) { $link->set_session_id($session_id); } $link->add(); return true; }
$keyword = Security::remove_XSS($_GET['search']); } if ($simple_search_form->validate() && empty($keyword)) { $keyword = $values['keyword']; } if (!empty($keyword)) { $cats = Category::load($category); $allcat = array(); if (isset($_GET['selectcat']) && $_GET['selectcat'] == 0 && isset($_GET['search'])) { $allcat = $cats[0]->get_subcategories(null); $allcat_info = Category::find_category($keyword, $allcat); $alleval = array(); $alllink = array(); } else { $alleval = Evaluation::find_evaluations($keyword, $cats[0]->get_id()); $alllink = LinkFactory::find_links($keyword, $cats[0]->get_id()); } } elseif (isset($_GET['studentoverview'])) { //@todo this code seems to be deprecated because the gradebook tab is off $cats = Category::load($category); $stud_id = api_is_allowed_to_edit() ? null : api_get_user_id(); $allcat = array(); $alleval = $cats[0]->get_evaluations($stud_id, true); $alllink = $cats[0]->get_links($stud_id, true); if (isset($_GET['exportpdf'])) { $datagen = new GradebookDataGenerator($allcat, $alleval, $alllink); $header_names = array(get_lang('Name'), get_lang('Description'), get_lang('Weight'), get_lang('Date'), get_lang('Results')); $data_array = $datagen->get_data(GradebookDataGenerator::GDG_SORT_NAME, 0, null, true); $newarray = array(); foreach ($data_array as $data) { $newarray[] = array_slice($data, 1);
private function build_edit_column($item) { $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id()); $locked_status = $this->evaluation->get_locked(); if (api_is_allowed_to_edit(null, true) && $locked_status == 0) { //api_is_course_admin() $edit_column = '<a href="' . api_get_self() . '?editres=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '&' . api_get_cidreq() . '">' . Display::return_icon('edit.png', get_lang('Modify'), '', '22') . '</a>'; $edit_column .= ' <a href="' . api_get_self() . '?delete_mark=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '&' . api_get_cidreq() . '">' . Display::return_icon('delete.png', get_lang('Delete'), '', '22') . '</a>'; } if ($this->evaluation->get_course_code() == null) { $edit_column .= ' <a href="' . api_get_self() . '?resultdelete=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '" onclick="return confirmationuser();"> <img src="../img/delete.gif" border="0" title="' . get_lang('Delete') . '" alt="" /></a>'; $edit_column .= ' <a href="user_stats.php?userid=' . $item['id'] . '&selecteval=' . $this->evaluation->get_id() . '&' . api_get_cidreq() . '"> <img src="../img/statistics.gif" width="17px" border="0" title="' . get_lang('Statistics') . '" alt="" /></a>'; } // Evaluation's origin is a link if ($this->evaluation->get_category_id() < 0) { $link = LinkFactory::get_evaluation_link($this->evaluation->get_id()); $doc_url = $link->get_view_url($item['id']); if ($doc_url != null) { $edit_column .= ' <a href="' . $doc_url . '" target="_blank">' . '<img src="' . api_get_path(WEB_CODE_PATH) . 'img/link.gif" border="0" title="' . get_lang('OpenDocument') . '" alt="" />' . '</a>'; } } return $edit_column; }
/** * Constructor * To add link, define category_object and link_type * To edit link, define link_object */ function LinkAddEditForm($form_type, $category_object, $link_type, $link_object, $form_name, $action = null) { parent::__construct($form_name, 'post', $action); // set or create link object if (isset($link_object)) { $link = $link_object; } elseif (isset($link_type) && isset($category_object)) { $link = LinkFactory::create($link_type); $link->set_course_code(api_get_course_id()); } else { die('LinkAddEditForm error: define link_type/category_object or link_object'); } $defaults = array(); $this->addElement('hidden', 'zero', 0); if (!empty($_GET['editlink'])) { $this->addElement('header', '', get_lang('EditLink')); } // ELEMENT: name if ($form_type == self::TYPE_ADD || $link->is_allowed_to_change_name()) { if ($link->needs_name_and_description()) { $this->add_textfield('name', get_lang('Name'), true, array('size' => '40', 'maxlength' => '40')); } else { $select = $this->addElement('select', 'select_link', get_lang('ChooseItem')); foreach ($link->get_all_links() as $newlink) { $select->addoption($newlink[1], $newlink[0]); } } } else { $this->addElement('label', get_lang('Name'), '<span class="freeze">' . $link->get_name() . ' [' . $link->get_type_name() . ']</span>'); $this->addElement('hidden', 'name_link', $link->get_name(), array('id' => 'name_link')); } if (count($category_object) == 1) { $this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id()); } else { $select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id')); $this->addRule('select_gradebook', get_lang('ThisFieldIsRequired'), 'nonzero'); $default_weight = 0; if (!empty($category_object)) { foreach ($category_object as $my_cat) { if ($my_cat->get_course_code() == api_get_course_id()) { $grade_model_id = $my_cat->get_grade_model_id(); if (empty($grade_model_id)) { if ($my_cat->get_parent_id() == 0) { $default_weight = $my_cat->get_weight(); $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); } else { $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); } } else { $select_gradebook->addoption(get_lang('Select'), 0); } if ($link->get_category_id() == $my_cat->get_id()) { $default_weight = $my_cat->get_weight(); } } } } } $this->add_textfield('weight_mask', array(get_lang('Weight'), null, ' [0 .. ' . $category_object[0]->get_weight() . '] '), true, array('size' => '4', 'maxlength' => '5', 'class' => 'span1')); $this->addElement('hidden', 'weight'); /* // ELEMENT: weight $this->add_textfield('weight', array(get_lang('Weight'), null, '/ <span id="max_weight">'.$default_weight.'</span>'), true, array ( 'size' => '4', 'maxlength' => '5', 'class' => 'span1' ));*/ $this->addRule('weight_mask', get_lang('OnlyNumbers'), 'numeric'); $this->addRule(array('weight_mask', 'zero'), get_lang('NegativeValue'), 'compare', '>='); if ($form_type == self::TYPE_EDIT) { $parent_cat = Category::load($link->get_category_id()); if ($parent_cat[0]->get_parent_id() == 0) { $values['weight'] = $link->get_weight(); } else { $cat = Category::load($parent_cat[0]->get_parent_id()); //$global_weight = $cat[0]->get_weight(); //$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight; //$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight; //$values['weight'] = $weight; $values['weight'] = $link->get_weight(); } $defaults['weight_mask'] = $values['weight']; $defaults['select_gradebook'] = $link->get_category_id(); } // ELEMENT: max if ($link->needs_max()) { if ($form_type == self::TYPE_EDIT && $link->has_results()) { $this->add_textfield('max', get_lang('QualificationNumeric'), false, array('size' => '4', 'maxlength' => '5', 'disabled' => 'disabled')); } else { $this->add_textfield('max', get_lang('QualificationNumeric'), true, array('size' => '4', 'maxlength' => '5')); $this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); $this->addRule(array('max', 'zero'), get_lang('NegativeValue'), 'compare', '>='); } if ($form_type == self::TYPE_EDIT) { $defaults['max'] = $link->get_max(); } } // ELEMENT: date //$this->add_datepicker('date',get_lang('Date')); //$defaults['date'] = ($form_type == self :: TYPE_EDIT ? $link->get_date() : time()); // ELEMENT: description if ($link->needs_name_and_description()) { $this->addElement('textarea', 'description', get_lang('Description'), array('rows' => '3', 'cols' => '34')); if ($form_type == self::TYPE_EDIT) { $defaults['description'] = $link->get_description(); } } // ELEMENT: visible $visible = $form_type == self::TYPE_EDIT && $link->is_visible() ? '1' : '0'; $this->addElement('checkbox', 'visible', null, get_lang('Visible'), $visible); if ($form_type == self::TYPE_EDIT) { $defaults['visible'] = $link->is_visible(); } // ELEMENT: add results if ($form_type == self::TYPE_ADD && $link->needs_results()) { $this->addElement('checkbox', 'addresult', get_lang('AddResult')); } // submit button if ($form_type == self::TYPE_ADD) { $this->addElement('style_submit_button', 'submit', get_lang('CreateLink'), 'class="save"'); } else { $this->addElement('style_submit_button', 'submit', get_lang('LinkMod'), 'class="save"'); } if ($form_type == self::TYPE_ADD) { $setting = api_get_setting('tool_visible_by_default_at_creation'); $visibility_default = 1; if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') { $visibility_default = 0; } $defaults['visible'] = $visibility_default; } // set default values $this->setDefaults($defaults); }
/** * Static admin function allowing removal of a learnpath * @param string Course code * @param integer Learnpath ID * @param string Whether to delete data or keep it (default: 'keep', others: 'remove') * @return boolean True on success, false on failure (might change that to return number of elements deleted) */ function delete($course = null, $id = null, $delete = 'keep') { //TODO implement a way of getting this to work when the current object is not set //In clear: implement this in the item class as well (abstract class) and use the given ID in queries //if(empty($course)){$course = api_get_course_id();} //if(empty($id)){$id = $this->get_id();} //If an ID is specifically given and the current LP is not the same, //prevent delete if (!empty($id) && $id != $this->lp_id) { return false; } $lp = Database::get_course_table(TABLE_LP_MAIN); $lp_item = Database::get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below. $lp_view = Database::get_course_table(TABLE_LP_VIEW); $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);} //delete lp item id foreach ($this->items as $id => $dummy) { //$this->items[$id]->delete(); $sql_del_view = "DELETE FROM {$lp_item_view} WHERE lp_item_id = '" . $id . "'"; $res_del_item_view = Database::query($sql_del_view, __FILE__, __LINE__); } // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673 $sql_del_item = "DELETE FROM {$lp_item} WHERE lp_id = " . $this->lp_id; $res_del_item = Database::query($sql_del_item, __FILE__, __LINE__); $sql_del_view = "DELETE FROM {$lp_view} WHERE lp_id = " . $this->lp_id; //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);} $res_del_view = Database::query($sql_del_view, __FILE__, __LINE__); $this->toggle_publish($this->lp_id, 'i'); //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);} if ($this->type == 2 or $this->type == 3) { //this is a scorm learning path, delete the files as well $sql = "SELECT path FROM {$lp} WHERE id = " . $this->lp_id; $res = Database::query($sql, __FILE__, __LINE__); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); $path = $row['path']; $sql = "SELECT id FROM {$lp} WHERE path = '{$path}' AND id != " . $this->lp_id; $res = Database::query($sql, __FILE__, __LINE__); if (Database::num_rows($res) > 0) { //another learning path uses this directory, so don't delete it if ($this->debug > 2) { error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0); } } else { //no other LP uses that directory, delete it $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty($course_scorm_dir)) { if ($this->debug > 2) { error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0); } // Proposed by Christophe (clefevre). if (strcmp(substr($path, -2), "/.") == 0) { $path = substr($path, 0, -1); // Remove "." at the end } //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way. rmdirr($course_scorm_dir . $path); } } } } $sql_del_lp = "DELETE FROM {$lp} WHERE id = " . $this->lp_id; //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);} $res_del_lp = Database::query($sql_del_lp, __FILE__, __LINE__); $this->update_display_order(); //updates the display order of all lps api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id()); require_once '../gradebook/lib/be.inc.php'; $tbl_grade_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); //delete link of gradebook tool $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";'; $result = Database::query($sql, __FILE__, __LINE__); $row = Database::fetch_array($result, 'ASSOC'); //fixing gradebook link deleted see #5229 if (!empty($row['id'])) { $link = LinkFactory::load($row['id']); if ($link[0] != null) { $link[0]->delete(); } } //TODO: also delete items and item-views if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) { require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id); } }
/* For licensing terms, see /license.txt */ /** * Script * @package chamilo.gradebook */ //$cidReset = true; require_once '../inc/global.inc.php'; api_block_anonymous_users(); GradebookUtils::block_students(); $tbl_grade_links = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); //selected name of database $course_id = GradebookUtils::get_course_id_by_link_id($_GET['editlink']); $tbl_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD); $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); $linkarray = LinkFactory::load($_GET['editlink']); $link = $linkarray[0]; if ($link->is_locked() && !api_is_platform_admin()) { api_not_allowed(); } $linkcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : ''; $linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']) : ''; $session_id = api_get_session_id(); if ($session_id == 0) { $cats = Category::load(null, null, $course_code, null, null, $session_id, false); //already init } else { $cats = Category::load_session_categories(null, $session_id); } $form = new LinkAddEditForm(LinkAddEditForm::TYPE_EDIT, $cats, null, $link, 'edit_link_form', api_get_self() . '?selectcat=' . $linkcat . '&editlink=' . $linkedit . '&' . api_get_cidreq()); if ($form->validate()) {
private function build_stud_label($id, $username, $lastname, $firstname) { $opendocurl_start = ''; $opendocurl_end = ''; // evaluation's origin is a link if ($this->evaluation_object->get_category_id() < 0) { $link = LinkFactory::get_evaluation_link($this->evaluation_object->get_id()); $doc_url = $link->get_view_url($id); if ($doc_url != null) { $opendocurl_start .= '<a href="' . $doc_url . '" target="_blank">'; $opendocurl_end = '</a>'; } } return $opendocurl_start . api_get_person_name($firstname, $lastname) . ' (' . $username . ')' . $opendocurl_end; }
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), api_get_course_info()); if (!$isDrhOfCourse) { GradebookUtils::block_students(); } $interbreadcrumb[] = array('url' => $_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook')); //load the evaluation & category $select_eval = Security::remove_XSS($_GET['selecteval']); if (empty($select_eval)) { api_not_allowed(); } $displayscore = ScoreDisplay::instance(); $eval = Evaluation::load($select_eval); $overwritescore = 0; if ($eval[0]->get_category_id() < 0) { // if category id is negative, then the evaluation's origin is a link $link = LinkFactory::get_evaluation_link($eval[0]->get_id()); $currentcat = Category::load($link->get_category_id()); } else { $currentcat = Category::load($eval[0]->get_category_id()); } //load the result with the evaluation id if (isset($_GET['delete_mark'])) { $result = Result::load($_GET['delete_mark']); if (!empty($result[0])) { $result[0]->delete(); } } if (isset($_GET['selecteval'])) { $allresults = Result::load(null, null, $select_eval); $iscourse = $currentcat[0]->get_course_code() == null ? 1 : 0; }
/** * @param $result * @return array */ private static function create_objects_from_sql_result($result) { $links = array(); while ($data = Database::fetch_array($result)) { $link = LinkFactory::create($data['type']); $link->set_id($data['id']); $link->set_type($data['type']); $link->set_ref_id($data['ref_id']); $link->set_user_id($data['user_id']); $link->set_course_code($data['course_code']); $link->set_category_id($data['category_id']); $link->set_date($data['created_at']); $link->set_weight($data['weight']); $link->set_visible($data['visible']); $link->set_locked($data['locked']); //session id should depend of the category --> $data['category_id'] $session_id = api_get_session_id(); $link->set_session_id($session_id); $links[] = $link; } return $links; }
/** * Get appropriate links visible for the user * @param int $stud_id student id (default: all students) * @param boolean $recursive process subcategories (default: no recursion) */ public function get_links($stud_id = null, $recursive = false, $course_code = '') { $links = array(); if (empty($course_code)) { $course_code = api_get_course_id(); } // no links in root or course independent categories if ($this->id == 0) { } elseif (isset($stud_id)) { // 1 student $stud_id $links = LinkFactory::load(null, null, null, null, empty($this->course_code) ? null : $course_code, $this->id, api_is_allowed_to_edit() ? null : 1); } elseif (api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) { // all students -> only for course/platform admin $links = LinkFactory::load(null, null, null, null, empty($this->course_code) ? null : $this->course_code, $this->id, null); } if ($recursive) { $subcats = $this->get_subcategories($stud_id, $course_code); if (!empty($subcats)) { foreach ($subcats as $subcat) { $sublinks = $subcat->get_links($stud_id, false, $course_code); $links = array_merge($links, $sublinks); } } } return $links; }
/** * @param $link * @param $courseCode * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink */ private function createLink($link, $courseCode) { $link = LinkFactory::create($link); if (!empty($courseCode)) { $link->set_course_code($courseCode); } elseif (!empty($_GET['course_code'])) { $link->set_course_code(Database::escape_string($_GET['course_code'], null, false)); } return $link; }
$category = Category::load($_GET['selectcat']); $url = api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&newtypeselected=' . $typeSelected . '&course_code=' . api_get_course_id() . '&' . api_get_cidreq(); $typeform = new LinkForm(LinkForm::TYPE_CREATE, $category[0], null, 'create_link', null, $url, $typeSelected); // if user selected a link type if ($typeform->validate() && isset($_GET['newtypeselected'])) { // reload page, this time with a parameter indicating the selected type header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&typeselected=' . $typeform->exportValue('select_link') . '&course_code=' . Security::remove_XSS($_GET['course_code']) . '&' . api_get_cidreq()); exit; } // link type selected, show 2nd form to retrieve the link data if (isset($typeSelected) && $typeSelected != '0') { $url = api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&typeselected=' . $typeSelected . '&course_code=' . $courseCode . '&' . api_get_cidreq(); $addform = new LinkAddEditForm(LinkAddEditForm::TYPE_ADD, $all_categories, $typeSelected, null, 'add_link', $url); if ($addform->validate()) { $addvalues = $addform->exportValues(); $link = LinkFactory::create($typeSelected); $link->set_user_id(api_get_user_id()); $link->set_course_code(api_get_course_id()); $link->set_category_id($addvalues['select_gradebook']); if ($link->needs_name_and_description()) { $link->set_name($addvalues['name']); } else { $link->set_ref_id($addvalues['select_link']); } $parent_cat = Category::load($addvalues['select_gradebook']); $global_weight = $category[0]->get_weight(); $link->set_weight($addvalues['weight_mask']); if ($link->needs_max()) { $link->set_max($addvalues['max']); } if ($link->needs_name_and_description()) {
break; case 'setinvisible': foreach ($_POST['id'] as $indexstr) { if (substr($indexstr, 0, 4) == 'CATE') { $cats = Category::load(substr($indexstr, 4)); $cats[0]->set_visible(0); $cats[0]->save(); $cats[0]->apply_visibility_to_children(); } if (substr($indexstr, 0, 4) == 'EVAL') { $eval = Evaluation::load(substr($indexstr, 4)); $eval[0]->set_visible(0); $eval[0]->save(); } if (substr($indexstr, 0, 4) == 'LINK') { $link = LinkFactory::load(substr($indexstr, 4)); $link[0]->set_visible(0); $link[0]->save(); } } $confirmation_message = get_lang('ItemsInVisible'); $filter_confirm_msg = false; break; } } } if (isset($_POST['submit']) && isset($_POST['keyword'])) { header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&search=' . Security::remove_XSS($_POST['keyword'])); exit; } // DISPLAY HEADERS AND MESSAGES
$category = Category::load($_GET['selectcat']); $url = api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&newtypeselected=' . (isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : '') . '&course_code=' . api_get_course_id(); $typeform = new LinkForm(LinkForm::TYPE_CREATE, $category[0], null, 'create_link', null, $url, $_GET['typeselected']); // if user selected a link type if ($typeform->validate() && isset($_GET['newtypeselected'])) { // reload page, this time with a parameter indicating the selected type header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&typeselected=' . $typeform->exportValue('select_link') . '&course_code=' . Security::remove_XSS($_GET['course_code'])); exit; } // link type selected, show 2nd form to retrieve the link data if (isset($_GET['typeselected']) && $_GET['typeselected'] != '0') { $url = api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&typeselected=' . Security::remove_XSS($_GET['typeselected']) . '&course_code=' . Security::remove_XSS($_GET['course_code']); $addform = new LinkAddEditForm(LinkAddEditForm::TYPE_ADD, $all_categories, intval($_GET['typeselected']), null, 'add_link', $url); if ($addform->validate()) { $addvalues = $addform->exportValues(); $link = LinkFactory::create($_GET['typeselected']); $link->set_user_id(api_get_user_id()); $link->set_course_code(api_get_course_id()); $link->set_category_id($addvalues['select_gradebook']); if ($link->needs_name_and_description()) { $link->set_name($addvalues['name']); } else { $link->set_ref_id($addvalues['select_link']); } $parent_cat = Category::load($addvalues['select_gradebook']); $global_weight = $category[0]->get_weight(); $link->set_weight($addvalues['weight_mask']); if ($link->needs_max()) { $link->set_max($addvalues['max']); } if ($link->needs_name_and_description()) {
/** * Create an AbsctrackLink array from GradebookLink \Doctrine\Common\Collections\ArrayCollection or array * @param \Doctrine\Common\Collections\ArrayCollection|array $entities * @return array */ private static function createObjectsFromEntities($entities) { $links = []; foreach ($entities as $gradebookLink) { $link = LinkFactory::create($gradebookLink->getType()); $link->set_id($gradebookLink->getId()); $link->set_type($gradebookLink->getType()); $link->set_ref_id($gradebookLink->getRefId()); $link->set_user_id($gradebookLink->getUserId()); $link->set_course_code($gradebookLink->getCourse()->getCode()); $link->set_category_id($gradebookLink->getCategoryId()); $link->set_date($gradebookLink->getCreatedAt()->format('Y-m-d h:m:i')); $link->set_weight($gradebookLink->getWeight()); $link->set_visible($gradebookLink->getVisible()); $link->set_locked($gradebookLink->getLocked()); //session id should depend of the category --> $data['category_id'] $session_id = api_get_session_id(); $link->set_session_id($session_id); $links[] = $link; } return $links; }