function get_body()
 {
     global $CFG, $CURMAN;
     $action = cm_get_param('action', '');
     $confirm = cm_get_param('confirm', '');
     //md5 confirmation hash
     $confirmuser = cm_get_param('confirmuser', 0);
     $trackid = cm_get_param('trackid', 0);
     $id = cm_get_param('id', 0);
     $sort = cm_get_param('sort', 'idnumber');
     $dir = cm_get_param('dir', 'ASC');
     $page = cm_get_param('page', 0);
     $perpage = cm_get_param('perpage', 30);
     // how many per page
     $namesearch = trim(cm_get_param('search', ''));
     $alpha = cm_get_param('alpha', '');
     if (!($track = new track($trackid))) {
         return ' (' . $trackid . ')';
     }
     switch ($action) {
         case 'add':
             return $this->get_add_form($trackid);
             break;
         case 'confirm':
             $tk = new trackassignmentclass($id);
             if (md5($tk->id) != $confirm) {
                 echo cm_error('Invalid confirmation code!');
             } else {
                 if (!$tk->delete()) {
                     echo cm_error('Course "name: ' . $tk->track->name . '" not deleted.');
                 }
             }
             break;
         case 'delete':
             return $this->get_delete_form($id);
             break;
         case 'edit':
             return $this->get_edit_form($id);
             break;
         case 'update':
             $id = cm_get_param('id', 0);
             $autoenrol = cm_get_param('autoenrol', 0);
             $trkassign = new trackassignmentclass($id);
             $trkassign->autoenrol = $autoenrol;
             $trkassign->data_update_record();
             break;
         case 'savenew':
             $classes = cm_get_param('classes', '');
             $classes = is_array($classes) ? $classes : array();
             $trackid = cm_get_param('trackid', 0, PARAM_INT);
             if (!empty($classes) and !empty($trackid)) {
                 $param = array('trackid' => $trackid);
                 $trackobj = new track($trackid);
                 foreach ($classes as $classid) {
                     $classobj = new cmclass($classid);
                     $param['classid'] = $classid;
                     $param['courseid'] = $classobj->courseid;
                     $param['autoenrol'] = 0;
                     $param['required'] = 0;
                     // Pull up the curricula assignment record(s)
                     $curcourse = curriculumcourse_get_list_by_curr($trackobj->curid);
                     // Traverse though curricula's courses until the the course the -
                     // selected classs is assigned to comes up
                     foreach ($curcourse as $recid => $curcourec) {
                         // Only interested in the course that the class is assigned to
                         if ($curcourec->courseid == $classobj->courseid) {
                             if ($curcourec->required) {
                                 $param['required'] = 1;
                                 // Only one class assigned to course to enable auto enrol
                                 if (1 == cmclass::count_course_assignments($curcourec->courseid)) {
                                     $param['autoenrol'] = 1;
                                 }
                             }
                         }
                     }
                     // Assign class to track now
                     $trkassignobj = new trackassignmentclass($param);
                     $trkassignobj->assign_class_to_track();
                 }
             }
             break;
     }
     $columns = array('clsname' => get_string('class_id_number', 'block_curr_admin'), 'autoenrol' => get_string('auto_enrol', 'block_curr_admin'));
     foreach ($columns as $column => $cdesc) {
         if ($sort != $column) {
             $columnicon = "";
             $columndir = "ASC";
         } else {
             $columndir = $dir == "ASC" ? "DESC" : "ASC";
             $columnicon = $dir == "ASC" ? "down" : "up";
             $columnicon = " <img src=\"{$CFG->pixpath}/t/{$columnicon}.gif\" alt=\"\" />";
         }
         ${$column} = "<a href=\"index.php?s=trkcls&amp;section=curr&amp;sort={$column}&amp;" . "dir={$columndir}&amp;search=" . urlencode(stripslashes($namesearch)) . "&amp;alpha={$alpha}&amp;trackid={$trackid}\">" . $cdesc . "</a>{$columnicon}";
         $table->head[] = ${$column};
         $table->align[] = 'left';
         $table->wrap[] = false;
     }
     $table->head[] = '';
     $table->align[] = 'center';
     $table->wrap[] = true;
     $trks = track_assignment_get_listing($trackid, $sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha);
     $numtrk = track_assignment_count_records($trackid, $namesearch, $alpha);
     $alphabet = explode(',', get_string('alphabet'));
     $strall = get_string('all');
     /// Nav bar information:
     $bc = '<div style="float:right;">' . $numtrk . ' track(s) found.</div>' . '<span class="breadcrumb">' . get_string('trackasso_manage_crumb', 'block_curr_admin', $track->name) . '</span>';
     echo cm_print_heading_block($bc, '', true);
     echo '<br />' . "\n";
     /// Bar of first initials
     echo "<p style=\"text-align:center\">";
     echo 'Name' . " : ";
     if ($alpha) {
         echo " <a href=\"index.php?s=trkcls&amp;section=curr&amp;sort=name&amp;dir=ASC&amp;" . "perpage={$perpage}&amp;trackid={$trackid}\">{$strall}</a> ";
     } else {
         echo " <b>{$strall}</b> ";
     }
     foreach ($alphabet as $letter) {
         if ($letter == $alpha) {
             echo " <b>{$letter}</b> ";
         } else {
             echo " <a href=\"index.php?s=trkcls&amp;section=curr&amp;sort=idnumber&amp;dir=ASC&amp;" . "perpage={$perpage}&amp;trackid={$trackid}&amp;alpha={$letter}\">{$letter}</a> ";
         }
     }
     echo "</p>";
     print_paging_bar($numtrk, $page, $perpage, "index.php?s=trkm&amp;section=curr&amp;sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}&amp;" . "alpha={$alpha}&amp;trackid={$trackid}&amp;search=" . urlencode(stripslashes($namesearch)) . "&amp;");
     if (!$trks) {
         $match = array();
         if ($namesearch !== '') {
             $match[] = s($namesearch);
         }
         if ($alpha) {
             $match[] = 'idnumber' . ": {$alpha}" . "___";
         }
         $matchstring = implode(", ", $match);
         echo get_string('no_matching_track_assign', 'block_curr_admin') . $matchstring;
         $table = NULL;
     } else {
         $table->width = "95%";
         foreach ($trks as $trk) {
             $deletebutton = '<a href="index.php?s=trkcls&amp;section=curr&amp;action=delete&amp;' . 'id=' . $trk->id . '">' . '<img src="pix/delete.gif" alt="Delete" title="Delete" /></a>';
             $editbutton = '<a href="index.php?s=trkcls&amp;section=curr&amp;action=edit&amp;id=' . $trk->id . '">' . '<img src="pix/edit.gif" alt="Edit" title="Edit" /></a>';
             /*$tagbutton    = '<a href="index.php?s=tagins&amp;section=curr&amp;t=cur&amp;i='.$trk->id.'">'.
                               '<img src="pix/tag.gif" alt="Tags" title="Tags" /></a>';
               $clusterbutton = '<a href="index.php?s=clutrk&amp;section=curr&amp;mode=trk&amp;' .
                             'track=' . $trk->id . '"><img src="pix/cluster.gif" alt="Clusters" '.
                             'title="Clusters" /></a>';*/
             $newarr = array();
             foreach ($columns as $column => $cdesc) {
                 if ($column == 'clsname') {
                     $newarr[] = '<a href="index.php?s=cls&section=curr&action=edit&id=' . $trk->classid . '">' . $trk->{$column} . '</a>';
                 } else {
                     $newarr[] = $trk->{$column};
                 }
             }
             $newarr[] = $editbutton . ' ' . $deletebutton;
             $table->data[] = $newarr;
         }
     }
     echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>";
     echo "<form action=\"index.php\" method=\"get\"><fieldset class=\"invisiblefieldset\">";
     echo '<input type="hidden" name="s" value="trkcls" />';
     echo '<input type="hidden" name="section" value="curr" />';
     echo '<input type="hidden" name="sort" value="' . $sort . '" />';
     echo '<input type="hidden" name="dir" value="' . $dir . '" />';
     echo '<input type="hidden" name="perpage" value="' . $perpage . '" />';
     echo '<input type="hidden" name="trackid" value="' . $trackid . '" />';
     echo "<input type=\"text\" name=\"search\" value=\"" . s($namesearch, true) . "\" size=\"40\" />";
     echo "<input type=\"submit\" value=\"" . get_string('search', 'block_curr_admin') . "\" />";
     if ($namesearch) {
         echo "<input type=\"button\" onclick=\"document.location='index.php?s=trkcls&amp;" . "section=curr&amp;sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}&amp;alpha={$alpha}&amp;trackid={$trackid}';\" " . "value=\"" . get_string('show_all_curricula', 'block_curr_admin') . "\" />";
     }
     echo "</fieldset></form>";
     echo "</td></tr></table>";
     if (!empty($table)) {
         print_heading('<a href="index.php?s=trkcls&amp;section=curr&amp;action=add&amp;trackid=' . $trackid . '">' . get_string('trackasso_add_asso', 'block_curr_admin', $track->name) . '</a>');
         print_table($table);
         print_paging_bar($numtrk, $page, $perpage, "index.php?s=trkcls&amp;section=curr&amp;sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}" . "&amp;alpha={$alpha}&amp;trackid={$trackid}&amp;search=" . urlencode(stripslashes($namesearch)) . "&amp;");
     }
     print_heading('<a href="index.php?s=trkcls&amp;section=curr&amp;action=add&amp;trackid=' . $trackid . '">' . get_string('trackasso_add_asso', 'block_curr_admin', $track->name) . '</a>');
 }
 /**
  * Clone a curriculum.
  * @param array $options options for cloning.  Valid options are:
  * - 'tracks': whether or not to clone tracks (default: false)
  * - 'courses': whether or not to clone courses (default: false)
  * - 'classes': whether or not to clone classes (default: false)
  * - 'moodlecourses': whether or not to clone Moodle courses (if they were
  *   autocreated).  Values can be (default: "copyalways"):
  *   - "copyalways": always copy course
  *   - "copyautocreated": only copy autocreated courses
  *   - "autocreatenew": autocreate new courses from course template
  *   - "link": link to existing course
  * - 'targetcluster': the cluster id or cluster object (if any) to
  *   associate the clones with (default: none)
  * @return array array of array of object IDs created.  Key in outer array
  * is type of object (plural).  Key in inner array is original object ID,
  * value is new object ID.  Outer array also has an entry called 'errors',
  * which is an array of any errors encountered when duplicating the
  * object.
  */
 function duplicate($options = array())
 {
     require_once CURMAN_DIRLOCATION . '/lib/track.class.php';
     $objs = array('errors' => array());
     if (isset($options['targetcluster'])) {
         $cluster = $options['targetcluster'];
         if (!is_object($cluster) || !is_a($cluster, 'cluster')) {
             $options['targetcluster'] = $cluster = new cluster($cluster);
         }
     }
     // clone main curriculum object
     $clone = new curriculum($this);
     unset($clone->id);
     if (isset($cluster)) {
         // if cluster specified, append cluster's name to curriculum
         $clone->name = $clone->name . ' - ' . $cluster->name;
         $clone->idnumber = $clone->idnumber . ' - ' . $cluster->name;
     }
     $clone = new curriculum(addslashes_recursive($clone));
     if (!$clone->add()) {
         $objs['errors'][] = get_string('failclustcpycurr', 'block_curr_admin', $this);
         return $objs;
     }
     $objs['curricula'] = array($this->id => $clone->id);
     $options['targetcurriculum'] = $clone->id;
     // associate with target cluster (if any)
     if (isset($cluster)) {
         clustercurriculum::associate($cluster->id, $clone->id);
     }
     if (!empty($options['courses'])) {
         // copy courses
         $currcrs = curriculumcourse_get_list_by_curr($this->id);
         if (!empty($currcrs)) {
             $objs['courses'] = array();
             $objs['classes'] = array();
             foreach ($currcrs as $currcrsdata) {
                 $course = new course($currcrsdata->courseid);
                 $rv = $course->duplicate($options);
                 if (isset($rv['errors']) && !empty($rv['errors'])) {
                     $objs['errors'] = array_merge($objs['errors'], $rv['errors']);
                 }
                 if (isset($rv['courses'])) {
                     $objs['courses'] = $objs['courses'] + $rv['courses'];
                 }
                 if (isset($rv['classes'])) {
                     $objs['classes'] = $objs['classes'] + $rv['classes'];
                 }
                 // associate with curriculum
                 if (isset($rv['courses'][$course->id])) {
                     $curcrs = new curriculumcourse($currcrsdata);
                     unset($curcrs->id);
                     $curcrs->courseid = $rv['courses'][$course->id];
                     $curcrs->curriculumid = $clone->id;
                     $curcrs->add();
                 }
             }
         }
     }
     if (!empty($objs['errors'])) {
         return $objs;
     }
     if (!empty($options['tracks'])) {
         // copy tracks
         $tracks = track_get_listing('name', 'ASC', 0, 0, '', '', $this->id);
         if (isset($objs['courses'])) {
             $options['coursemap'] = $objs['courses'];
         }
         if (!empty($tracks)) {
             $objs['tracks'] = array();
             if (isset($objs['courses'])) {
                 $options['coursemap'] = $objs['courses'];
             }
             if (!isset($objs['classes'])) {
                 $objs['classes'] = array();
             }
             foreach ($tracks as $track) {
                 $track = new track($track);
                 $options['classmap'] = $objs['classes'];
                 $rv = $track->duplicate($options);
                 if (isset($rv['errors']) && !empty($rv['errors'])) {
                     $objs['errors'] = array_merge($objs['errors'], $rv['errors']);
                 }
                 if (isset($rv['tracks'])) {
                     $objs['tracks'] = $objs['tracks'] + $rv['tracks'];
                 }
                 if (isset($rv['classes'])) {
                     $objs['classes'] = $objs['classes'] + $rv['classes'];
                 }
             }
         }
     }
     return $objs;
 }
Example #3
0
 /**
  * Clone a curriculum.
  * @param array $options options for cloning.  Valid options are:
  * - 'tracks': whether or not to clone tracks (default: false)
  * - 'courses': whether or not to clone courses (default: false)
  * - 'classes': whether or not to clone classes (default: false)
  * - 'moodlecourses': whether or not to clone Moodle courses (if they were
  *   autocreated).  Values can be (default: "copyalways"):
  *   - "copyalways": always copy course
  *   - "copyautocreated": only copy autocreated courses
  *   - "autocreatenew": autocreate new courses from course template
  *   - "link": link to existing course
  * - 'targetcluster': the cluster id or cluster object (if any) to
  *   associate the clones with (default: none)
  * @return array array of array of object IDs created.  Key in outer array
  * is type of object (plural).  Key in inner array is original object ID,
  * value is new object ID.  Outer array also has an entry called 'errors',
  * which is an array of any errors encountered when duplicating the
  * object.
  */
 function duplicate(array $options = array())
 {
     require_once elispm::lib('data/track.class.php');
     $objs = array('errors' => array());
     if (isset($options['targetcluster'])) {
         $userset = $options['targetcluster'];
         if (!is_object($userset) || !is_a($userset, 'userset')) {
             $options['targetcluster'] = $userset = new userset($userset);
         }
     }
     // Due to lazy loading, we need to pre-load this object
     $this->load();
     // clone main curriculum object
     $clone = new curriculum($this);
     unset($clone->id);
     $idnumber = $clone->idnumber;
     $name = $clone->name;
     if (isset($userset)) {
         $to_append = ' - ' . $userset->name;
         // if cluster specified, append cluster's name to curriculum
         $idnumber = append_once($idnumber, $to_append, array('maxlength' => 95));
         $name = append_once($name, $to_append, array('maxlength' => 59));
     }
     //get a unique idnumber
     $clone->idnumber = generate_unique_identifier(curriculum::TABLE, 'idnumber', $idnumber, array('idnumber' => $idnumber));
     if ($clone->idnumber != $idnumber) {
         //get the suffix appended and add it to the name
         $parts = explode('.', $clone->idnumber);
         $suffix = end($parts);
         $clone->name = $name . '.' . $suffix;
     } else {
         $clone->name = $name;
     }
     $clone = new curriculum($clone);
     $clone->save();
     $objs['curricula'] = array($this->id => $clone->id);
     $options['targetcurriculum'] = $clone->id;
     // associate with target cluster (if any)
     if (isset($userset)) {
         clustercurriculum::associate($userset->id, $clone->id);
     }
     if (!empty($options['courses'])) {
         // copy courses
         $currcrs = curriculumcourse_get_list_by_curr($this->id);
         if ($currcrs->valid()) {
             $objs['courses'] = array();
             $objs['classes'] = array();
             foreach ($currcrs as $currcrsdata) {
                 $course = new course($currcrsdata->courseid);
                 $rv = $course->duplicate($options);
                 if (isset($rv['errors']) && !empty($rv['errors'])) {
                     $objs['errors'] = array_merge($objs['errors'], $rv['errors']);
                 }
                 if (isset($rv['courses'])) {
                     $objs['courses'] = $objs['courses'] + $rv['courses'];
                 }
                 if (isset($rv['classes'])) {
                     $objs['classes'] = $objs['classes'] + $rv['classes'];
                 }
                 // associate with curriculum
                 if (isset($rv['courses'][$course->id])) {
                     $curcrs = new curriculumcourse($currcrsdata);
                     unset($curcrs->id);
                     $curcrs->courseid = $rv['courses'][$course->id];
                     $curcrs->curriculumid = $clone->id;
                     $curcrs->save();
                 }
             }
         }
         unset($currcrs);
     }
     if (!empty($objs['errors'])) {
         return $objs;
     }
     if (!empty($options['tracks'])) {
         // copy tracks
         $tracks = track_get_listing('name', 'ASC', 0, 0, '', '', $this->id);
         if (isset($objs['courses'])) {
             $options['coursemap'] = $objs['courses'];
         }
         if (!empty($tracks)) {
             $objs['tracks'] = array();
             if (isset($objs['courses'])) {
                 $options['coursemap'] = $objs['courses'];
             }
             if (!isset($objs['classes'])) {
                 $objs['classes'] = array();
             }
             foreach ($tracks as $track) {
                 $track = new track($track);
                 $options['classmap'] = $objs['classes'];
                 $rv = $track->duplicate($options);
                 if (isset($rv['errors']) && !empty($rv['errors'])) {
                     $objs['errors'] = array_merge($objs['errors'], $rv['errors']);
                 }
                 if (isset($rv['tracks'])) {
                     $objs['tracks'] = $objs['tracks'] + $rv['tracks'];
                 }
                 if (isset($rv['classes'])) {
                     $objs['classes'] = $objs['classes'] + $rv['classes'];
                 }
             }
         }
     }
     return $objs;
 }