Ejemplo n.º 1
0
/**
* Get child page ids of selected page.
*
* @param int $parentid
* @return array An array of ids.
*/
function cms_get_children_ids($parentid)
{
    static $childrenids;
    $parentid = intval($parentid);
    if (empty($childrenids)) {
        $childrenids = array();
    }
    if ($children = get_records("cmsnavi_data", "parentid", $parentid)) {
        foreach ($children as $child) {
            array_push($childrenids, intval($child->pageid));
            cms_get_children_ids($child->pageid);
        }
    }
    return $childrenids;
}
Ejemplo n.º 2
0
 // commented out and replaced according to: http://moodle.org/mod/forum/discuss.php?d=62456
 // $page->parentid = !empty($page->parentid) ? intval($page->parentid) : 0;
 $page->parentid = 0;
 if (isset($page->parentname)) {
     $page->parentname = clean_param($page->parentname, PARAM_FILE);
     if (!($parentid = get_field('cmsnavi_data', 'pageid', 'pagename', $page->parentname))) {
         $parentid = 0;
     }
     $page->parentid = $parentid;
 }
 // If menu has been changed set parentid to zero.
 // And get all pages underneath this page and move them too
 // into that new menu.
 $oldnaviid = get_field("cmsnavi_data", "naviid", "id", $page->id);
 if (intval($oldnaviid) !== intval($page->naviid)) {
     $children = cms_get_children_ids($page->pageid);
     foreach ($children as $childid) {
         if (!set_field("cmsnavi_data", "naviid", $page->naviid, "pageid", $childid)) {
             error("Cannot modify menu information for child pages!", "{$CFG->wwwroot}/cms/pages.php?course={$course->id}" . "&menuid={$oldnaviid}");
         }
     }
     $page->parentid = 0;
     $page->sortorder = 2000;
 }
 if (!empty($page->url)) {
     $page->url = clean_param($page->url, PARAM_URL);
     $page->target = $page->target != '_blank' ? '_top' : '_blank';
 } else {
     $page->url = '';
     $page->target = '';
 }
Ejemplo n.º 3
0
 if (!empty($pagecancel)) {
     redirect("pages.php?course={$course->id}&menuid={$pagenaviid}&sesskey={$USER->sesskey}");
 }
 // Get page data to see if this user can delete this page.
 $page->id = optional_param('id', 0, PARAM_INT);
 if (!($navidata = get_record("cmsnavi_data", "pageid", $page->id))) {
     redirect("pages.php?course={$course->id}&menuid={$pagenaviid}&sesskey={$USER->sesskey}", "Could not get navidata! You cant delete this page!", 2);
 }
 if (!($navi = get_record("cmsnavi", "id", $navidata->naviid))) {
     redirect("pages.php?course={$course->id}&menuid={$pagenaviid}&sesskey={$USER->sesskey}", "Could not get navi and course id's! You cant delete this page!", 2);
 }
 if (intval($navi->course) !== intval($course->id)) {
     error("You have no rights to delete page {$navidata->title}", "{$CFG->wwwroot}/");
 }
 // Delete child pages first if any.
 $childpages = cms_get_children_ids($page->id);
 if (!empty($childpages)) {
     foreach ($childpages as $childpage) {
         delete_records("cmspages", "id", $childpage);
         delete_records("cmsnavi_data", "pageid", $childpage);
     }
 }
 // Delete page first
 if (!delete_records("cmspages", "id", $page->id)) {
     error("Could not delete page!");
 }
 // Delete navidata
 if (!delete_records("cmsnavi_data", "id", $navidata->id)) {
     error("Could not delete navigation data!");
 }
 // Delete page history.