Exemplo n.º 1
0
/**
 * @package  DoceboLms
 * @subpackage  menu managment
 * @version  $Id: lib.manmenu.php 813 2006-11-27 15:45:33Z fabio $
 * @category Course menu managment
 * @author	 Fabio Pirovano 
 */
function cerateCourseMenuFromCustom($id_custom, $id_course, $group_idst)
{
    $acl_man =& Docebo::user()->getAclManager();
    $re_main = sql_query("\r\n\t\tSELECT idMain, sequence, name, image\r\n\t\tFROM %lms_menucustom_main\r\n\t\tWHERE idCustom = '" . $id_custom . "'");
    $main_values = array();
    $query_ins_main = "\r\n\tINSERT INTO %lms_menucourse_main (idCourse, sequence, name, image ) VALUES";
    while (list($id_main, $seq, $name, $image) = sql_fetch_row($re_main)) {
        if (!sql_query($query_ins_main . " ( '" . $id_course . "','" . $seq . "', '" . addslashes($name) . "', '" . $image . "')")) {
            $map_main_id[$id_main] = false;
        } else {
            list($map_main_id[$id_main]) = sql_fetch_row(sql_query("SELECT LAST_INSERT_ID()"));
        }
    }
    // copy module ------------------------------------------
    $re_module = sql_query("\r\n\t\tSELECT idModule, idMain, sequence, my_name\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_menucustom_under\r\n\t\tWHERE idCustom = '" . $id_custom . "'");
    $module_values = array();
    $re = true;
    $query_ins_module = "INSERT INTO %lms_menucourse_under ( idCourse, idModule, idMain, sequence, my_name ) VALUES";
    while (list($id_module, $id_main, $seq, $my_name) = sql_fetch_row($re_module)) {
        if (isset($map_main_id[$id_main]) && $map_main_id[$id_main] !== false) {
            $re &= sql_query($query_ins_module . " ('" . $id_course . "', '" . $id_module . "', '" . $map_main_id[$id_main] . "', '" . $seq . "', '" . $my_name . "')");
        }
    }
    //copy module permission
    $group_of_from =& getCustomLevelSt($id_custom);
    $perm_form =& createPermForCourse($group_of_from, $id_course);
    $levels = CourseLevel::getLevels();
    foreach ($levels as $lv => $name_level) {
        foreach ($perm_form[$lv] as $idrole => $v) {
            if ($group_idst[$lv] != 0 && $idrole != 0) {
                $acl_man->addToRole($idrole, $group_idst[$lv]);
            }
        }
    }
    return $re;
}
Exemplo n.º 2
0
function removeModule($id_module, $id_main, $id_custom)
{
    $acl_man =& Docebo::user()->getAclManager();
    // Load module info
    $query_module = "\r\n\tSELECT module_name, default_name, file_name, class_name \r\n\tFROM " . $GLOBALS['prefix_lms'] . "_module \r\n\tWHERE idModule = '" . $id_module . "'";
    list($module_name, $name_db, $file_name, $class_name) = sql_fetch_row(sql_query($query_module));
    $module_obj =& createLmsModule($module_name);
    $levels = CourseLevel::getLevels();
    $all_token = $module_obj->getAllToken();
    // corresponding of token -> idst role
    $map_idst_token =& getModuleRoleSt($module_name, $all_token);
    // corresponding of level -> idst level
    $map_idst_level =& getCustomLevelSt($id_custom);
    // old permission of all module
    $actual_perm =& getAllModulesPermissionSt($map_idst_level, array_flip($map_idst_token));
    $re = true;
    foreach ($levels as $lv => $name_level) {
        $idlevel = $map_idst_level[$lv];
        foreach ($actual_perm[$lv] as $idrole => $v) {
            $acl_man->removeFromRole($idrole, $idlevel);
        }
    }
    if ($re) {
        $re = sql_query("\r\n\t\tDELETE FROM " . $GLOBALS['prefix_lms'] . "_menucustom_under \r\n\t\tWHERE idMain = '" . (int) $id_main . "' AND idModule = '" . (int) $id_module . "'");
    }
    return $re;
}