Пример #1
0
 function importcourse()
 {
     checkPerm('mod');
     require_once _base_ . '/lib/lib.form.php';
     require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
     require_once $GLOBALS['where_lms'] . '/lib/lib.coursepath.php';
     $out =& $GLOBALS['page'];
     $lang =& DoceboLanguage::createInstance('coursepath', 'lms');
     $id_path = importVar('id_path', true, 0);
     $id_slot = importVar('id_slot', true, 0);
     $selector = new Selector_Course();
     $selector->parseForState($_POST);
     $path_man = new CoursePath_Manager();
     if (isset($_GET['load'])) {
         $initial_selection = $path_man->getSlotElem($id_path, $id_slot);
         if (isset($_GET['load'])) {
             $selector->resetSelection($initial_selection);
         }
     }
     if (isset($_POST['import'])) {
         $initial_selection = $path_man->getSlotElem($id_path, $id_slot);
         $selected_courses = $selector->getSelection();
         $to_add = array_diff($selected_courses, $initial_selection);
         $to_del = array_diff($initial_selection, $selected_courses);
         $re = true;
         $added_courses = array();
         $removed_courses = array();
         while (list(, $id_c) = each($to_add)) {
             $re_s = $path_man->addToSlot($id_path, $id_slot, $id_c);
             if ($re_s) {
                 $added_courses[] = $id_c;
             }
             $re &= $re_s;
         }
         while (list(, $id_c) = each($to_del)) {
             $re_s = $path_man->delFromSlot($id_path, $id_slot, $id_c);
             if ($re_s) {
                 $removed_courses[] = $id_c;
             }
             $re &= $re_s;
         }
         // update users course subscription
         require_once $GLOBALS['where_lms'] . '/lib/lib.coursepath.php';
         require_once $GLOBALS['where_lms'] . '/lib/lib.subscribe.php';
         $cpath_man = new CoursePath_Manager();
         $subs_man = new CourseSubscribe_Management();
         $users = $cpath_man->getSubscribed($id_path);
         if (!empty($added_courses) && !empty($users)) {
             $re &= $subs_man->multipleSubscribe($users, $added_courses, 3);
         }
         if (!$re) {
             die('<a href="index.php?modname=coursepath&op=pathelem&id_path=' . $id_path . '">waths happen in insert ???</a>');
         }
         if (!empty($removed_courses) && !empty($users)) {
             $re &= $subs_man->multipleUnsubscribe($users, $removed_courses);
         }
         $cpath_man->fixSequence($id_path, $id_slot);
         Util::jump_to('index.php?modname=coursepath&op=pathelem&id_path=' . $id_path . '&result=' . ($re ? 'ok' : 'err'));
     }
     $query_pathlist = "\r\n\tSELECT path_name, path_descr\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursepath\r\n\tWHERE id_path = '" . (int) $id_path . "'\r\n\tORDER BY path_name";
     list($path_name, $path_descr) = sql_fetch_row(sql_query($query_pathlist));
     $page_title = array('index.php?modname=coursepath&amp;op=pathlist' => $lang->def('_COURSEPATH'), 'index.php?modname=coursepath&amp;op=pathelem&amp;id_path=' . $id_path => $path_name, $lang->def('_IMPORT_COURSE'));
     $out->add(getTitleArea($page_title, 'coursepath') . '<div class="std_block">' . Form::openForm('mancoursepath', 'index.php?modname=coursepath&amp;op=importcourse') . Form::getHidden('id_path', 'id_path', $id_path) . Form::getHidden('id_slot', 'id_slot', $id_slot), 'content');
     $selector->loadCourseSelector(false, true);
     $out->add(Form::openButtonSpace() . Form::getBreakRow() . Form::getButton('import', 'import', $lang->def('_IMPORT')) . Form::getButton('undoelem', 'undoelem', $lang->def('_UNDO')) . Form::closeButtonSpace() . Form::closeForm() . '</div>', 'content');
 }