function duplicateCourse() { $id_dupcourse = Get::req('id_course', DOTY_INT, 0); // read the old course info $query_sel = "SELECT *\n\tFROM " . $GLOBALS['prefix_lms'] . "_course\n\tWHERE idCourse = '" . $id_dupcourse . "' "; $result_sel = sql_query($query_sel); $list_sel = sql_fetch_array($result_sel); foreach ($list_sel as $k => $v) { $list_sel[$k] = mysql_escape_string($v); } $new_course_dup = 0; $new_file_array = array(); if ($list_sel['imgSponsor'] !== '') { $new_name_array = explode('_', str_replace('course_sponsor_logo_', '', $list_sel['imgSponsor'])); $filename = 'course_sponsor_logo_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_sponsor_logo_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['imgSponsor']); $new_file_array[0]['old'] = $list_sel['imgSponsor']; $new_file_array[0]['new'] = $filename; $list_sel['imgSponsor'] = $filename; } if ($list_sel['img_course'] !== '') { $new_name_array = explode('_', str_replace('course_logo_', '', $list_sel['img_course'])); $filename = 'course_logo_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_logo_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['img_course']); $new_file_array[1]['old'] = $list_sel['img_course']; $new_file_array[1]['new'] = $filename; $list_sel['img_course'] = $filename; } if ($list_sel['img_material'] !== '') { $new_name_array = explode('_', str_replace('course_user_material_', '', $list_sel['img_material'])); $filename = 'course_user_material_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_user_material_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['img_material']); $new_file_array[2]['old'] = $list_sel['img_material']; $new_file_array[2]['new'] = $filename; $list_sel['img_material'] = $filename; } if ($list_sel['img_othermaterial'] !== '') { $new_name_array = explode('_', str_replace('course_otheruser_material_', '', $list_sel['img_othermaterial'])); $filename = 'course_otheruser_material_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_otheruser_material_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['img_othermaterial']); $new_file_array[3]['old'] = $list_sel['img_othermaterial']; $new_file_array[3]['new'] = $filename; $list_sel['img_othermaterial'] = $filename; } if ($list_sel['course_demo'] !== '') { $new_name_array = explode('_', str_replace('course_demo_', '', $list_sel['course_demo'])); $filename = 'course_demo_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_demo_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['course_demo']); $new_file_array[4]['old'] = $list_sel['course_demo']; $new_file_array[4]['new'] = $filename; $list_sel['course_demo'] = $filename; } // duplicate the entry of learning_course $query_ins = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_course\n\t\t( idCategory, code, name, description, lang_code, status, level_show_user,\n\t\tsubscribe_method, linkSponsor, imgSponsor, img_course, img_material, img_othermaterial,\n\t\tcourse_demo, mediumTime, permCloseLO, userStatusOp, difficult, show_progress, show_time, show_extra_info,\n\t\tshow_rules, valid_time, max_num_subscribe, min_num_subscribe,\n\t\tmax_sms_budget, selling, prize, course_type, policy_point, point_to_all, course_edition, classrooms, certificates,\n\t\tcreate_date, security_code, imported_from_connection, course_quota, used_space, course_vote, allow_overbooking, can_subscribe,\n\t\tsub_start_date, sub_end_date, advance, show_who_online, direct_play, autoregistration_code, use_logo_in_courselist )\n\tVALUES\n\t\t( '" . $list_sel['idCategory'] . "', '" . $list_sel['code'] . "', '" . "Copia di " . $list_sel['name'] . "', '" . $list_sel['description'] . "', '" . $list_sel['lang_code'] . "', '" . $list_sel['status'] . "', '" . $list_sel['level_show_user'] . "',\n\t\t'" . $list_sel['subscribe_method'] . "', '" . $list_sel['linkSponsor'] . "', '" . $list_sel['imgSponsor'] . "', '" . $list_sel['img_course'] . "', '" . $list_sel['img_material'] . "', '" . $list_sel['img_othermaterial'] . "',\n\t\t'" . $list_sel['course_demo'] . "', '" . $list_sel['mediumTime'] . "', '" . $list_sel['permCloseLO'] . "', '" . $list_sel['userStatusOp'] . "', '" . $list_sel['difficult'] . "', '" . $list_sel['show_progress'] . "', '" . $list_sel['show_time'] . "', '" . $list_sel['show_extra_info'] . "',\n\t\t'" . $list_sel['show_rules'] . "', '" . $list_sel['valid_time'] . "', '" . $list_sel['max_num_subscribe'] . "', '" . $list_sel['min_num_subscribe'] . "',\n\t\t'" . $list_sel['max_sms_budget'] . "', '" . $list_sel['selling'] . "', '" . $list_sel['prize'] . "', '" . $list_sel['course_type'] . "', '" . $list_sel['policy_point'] . "', '" . $list_sel['point_to_all'] . "', '" . $list_sel['course_edition'] . "', '" . $list_sel['classrooms'] . "', '" . $list_sel['certificates'] . "',\n\t\t'" . $list_sel['create_date'] . "', '" . $list_sel['security_code'] . "', '" . $list_sel['imported_from_connection'] . "', '" . $list_sel['course_quota'] . "', '" . $list_sel['used_space'] . "', '" . $list_sel['course_vote'] . "', '" . $list_sel['allow_overbooking'] . "', '" . $list_sel['can_subscribe'] . "',\n\t\t'" . $list_sel['sub_start_date'] . "', '" . $list_sel['sub_end_date'] . "', '" . $list_sel['advance'] . "', '" . $list_sel['show_who_online'] . "', '" . $list_sel['direct_play'] . "', '" . $list_sel['autoregistration_code'] . "', '" . $list_sel['use_logo_in_courselist'] . "' )"; $result_ins = sql_query($query_ins); if (!$result_ins) { //Util::jump_to('index.php?modname=course&op=course_list&result=err_course'); return false; } // the id of the new course created $new_course_dup = sql_insert_id(); //Create the new course file $path = Get::sett('pathcourse'); $path = '/appLms/' . Get::sett('pathcourse') . (substr($path, -1) != '/' && substr($path, -1) != '\\' ? '/' : ''); require_once _base_ . '/lib/lib.upload.php'; sl_open_fileoperations(); foreach ($new_file_array as $file_info) { sl_copy($path . $file_info['old'], $path . $file_info['new']); } sl_close_fileoperations(); // copy the old course menu into the new one $query_selmen = "SELECT *\n\tFROM " . $GLOBALS['prefix_lms'] . "_menucourse_main\n\tWHERE idCourse = '" . $id_dupcourse . "' "; $result_selmen = sql_query($query_selmen); while ($list_selmen = sql_fetch_array($result_selmen)) { $query_dupmen = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_menucourse_main " . " (idCourse, sequence, name, image) " . " VALUES " . " ( '" . $new_course_dup . "', '" . $list_selmen['sequence'] . "', '" . $list_selmen['name'] . "', '" . $list_selmen['image'] . "' )"; $result_dupmen = sql_query($query_dupmen); $array_seq[$list_selmen['idMain']] = sql_insert_id(); } $query_selmenun = "SELECT *\n\tFROM " . $GLOBALS['prefix_lms'] . "_menucourse_under\n\tWHERE idCourse = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($list_selmenun = sql_fetch_array($result_selmenun)) { $valore_idn = $list_selmenun['idMain']; $_idMain = $array_seq[$valore_idn]; $query_dupmen = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_menucourse_under\n\t\t(idMain, idCourse, sequence, idModule, my_name)\n\t\tVALUES\n\t\t('" . $_idMain . "', '" . $new_course_dup . "', '" . $list_selmenun['sequence'] . "', '" . $list_selmenun['idModule'] . "', '" . $list_selmenun['my_name'] . "')"; $result_dupmen = sql_query($query_dupmen); } function &getCourseLevelSt($id_course) { $map = array(); $levels = CourseLevel::getLevels(); $acl_man =& $GLOBALS['current_user']->getAclManager(); // find all the group created for this menu custom for permission management foreach ($levels as $lv => $name_level) { $group_info = $acl_man->getGroup(FALSE, '/lms/course/' . $id_course . '/subscribed/' . $lv); $map[$lv] = $group_info[ACL_INFO_IDST]; } return $map; } function funAccess($functionname, $mode, $returnValue = false, $custom_mod_name = false) { return true; } require_once $GLOBALS['where_lms'] . '/lib/lib.course.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.manmenu.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.subscribe.php'; $docebo_course = new DoceboCourse($id_dupcourse); $subscribe_man = new CourseSubscribe_Manager(); $group_idst =& $docebo_course->createCourseLevel($new_course_dup); $group_of_from =& $docebo_course->getCourseLevel($id_dupcourse); $perm_form =& createPermForCoursebis($group_of_from, $new_course_dup, $id_dupcourse); $levels = $subscribe_man->getUserLevel(); foreach ($levels as $lv => $name_level) { foreach ($perm_form[$lv] as $idrole => $v) { if ($group_idst[$lv] != 0 && $idrole != 0) { $acl_man =& $GLOBALS['current_user']->getAclManager(); $acl_man->addToRole($idrole, $group_idst[$lv]); } } } // duplicate the certificate assigned $query_selmenun = "SELECT *\n\tFROM " . $GLOBALS['prefix_lms'] . "_certificate_course\n\tWHERE id_course = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($list_selmenun = sql_fetch_array($result_selmenun)) { $query_dupmen = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_certificate_course\n\t\t\t(id_certificate, id_course, available_for_status)\n\t\t\tVALUES\n\t\t\t('" . $list_selmenun['id_certificate'] . "', '" . $new_course_dup . "', '" . $list_selmenun['available_for_status'] . "' )"; $result_dupmen = sql_query($query_dupmen); } require_once $GLOBALS['where_lms'] . '/modules/organization/orglib.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.param.php'; require_once $GLOBALS['where_lms'] . '/class.module/track.object.php'; require_once $GLOBALS['where_lms'] . '/class.module/learning.object.php'; function createLO($objectType, $idResource = NULL) { $query = "SELECT className, fileName FROM " . $GLOBALS['prefix_lms'] . "_lo_types WHERE objectType='" . $objectType . "'"; $rs = sql_query($query); list($className, $fileName) = sql_fetch_row($rs); require_once $GLOBALS['where_lms'] . '/class.module/' . $fileName; $lo = new $className($idResource); return $lo; } $nullVal = NULL; $array_cor = array(); $map_org = array(); $tree_course = new OrgDirDb($id_dupcourse); $coll = $tree_course->getFoldersCollection($nullVal); while ($folder = $coll->getNext()) { //if($folder->otherValues[REPOFIELDIDRESOURCE] != 0 ) { if (!empty($folder->otherValues[REPOFIELDOBJECTTYPE])) { $lo = createLO($folder->otherValues[REPOFIELDOBJECTTYPE]); $id_nuovo_lo = $lo->copy($folder->otherValues[REPOFIELDIDRESOURCE]); $id_vecchio = $folder->otherValues[REPOFIELDIDRESOURCE]; $query_selmenun = "SELECT * FROM\n\t\t\t" . $GLOBALS['prefix_lms'] . "_organization\n\t\t\tWHERE idCourse = '" . $id_dupcourse . "'\n\t\t\tAND idResource = '" . $id_vecchio . "' "; $result_selmenun = sql_query($query_selmenun); while ($list_selmenun = mysql_fetch_array($result_selmenun)) { $query_dupmen = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_organization\n\t\t\t\t(idParent, path, lev, title,\n\t\t\t\tobjectType, idResource, idCategory, idUser, idAuthor,\n\t\t\t\tversion, difficult, description, language, resource,\n\t\t\t\tobjective, dateInsert, idCourse, prerequisites, isTerminator,\n\t\t\t\tidParam, visible, milestone)\n\t\t\t\tVALUES\n\t\t\t\t('" . (isset($map_org[$list_selmenun['idParent']]) ? $map_org[$list_selmenun['idParent']] : 0) . "', '" . $list_selmenun['path'] . "', '" . $list_selmenun['lev'] . "', '" . $list_selmenun['title'] . "',\n\t\t\t\t'" . $list_selmenun['objectType'] . "', '" . $id_nuovo_lo . "', '" . $list_selmenun['idCategory'] . "', '" . $list_selmenun['idUser'] . "', '" . $list_selmenun['idAuthor'] . "',\n\t\t\t\t'" . $list_selmenun['version'] . "', '" . $list_selmenun['difficult'] . "', '" . $list_selmenun['description'] . "', '" . $list_selmenun['language'] . "', '" . $list_selmenun['resource'] . "',\n\t\t\t\t'" . $list_selmenun['objective'] . "', '" . $list_selmenun['dateInsert'] . "', '" . $new_course_dup . "', '" . $list_selmenun['prerequisites'] . "', '" . $list_selmenun['isTerminator'] . "',\n\t\t\t\t'" . $list_selmenun['idParam'] . "', '" . $list_selmenun['visible'] . "', '" . $list_selmenun['milestone'] . "')"; $result_dupmen = sql_query($query_dupmen); $id_org = $list_selmenun['idOrg']; $id_last = sql_insert_id(); $array_cor[$id_org] = $id_last; $query_lo_par = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_lo_param\n\t\t\t\t(param_name, param_value)\n\t\t\t\tVALUES\n\t\t\t\t('idReference', '" . $id_last . "') "; $result_lo_par = sql_query($query_lo_par); $id_lo_par = sql_insert_id(); $query_up_lo = "UPDATE " . $GLOBALS['prefix_lms'] . "_lo_param\n\t\t\t\tSET idParam = '" . $id_lo_par . "'\n\t\t\t\tWHERE id = '" . $id_lo_par . "' "; $result_up_lo = sql_query($query_up_lo); $query_up_or = "UPDATE " . $GLOBALS['prefix_lms'] . "_organization\n\t\t\t\tSET\tidParam = '" . $id_lo_par . "'\n\t\t\t\tWHERE idOrg = '" . $id_last . "' "; $result_up_or = sql_query($query_up_or); } } else { // copy folder echo $id_vecchio = $folder->id; $query_selmenun = "SELECT * FROM\n\t\t\t" . $GLOBALS['prefix_lms'] . "_organization\n\t\t\tWHERE idCourse = '" . $id_dupcourse . "'\n\t\t\tAND idOrg = '" . $id_vecchio . "' "; $result_selmenun = sql_query($query_selmenun); $list_selmenun = mysql_fetch_array($result_selmenun); $query_dupmen = " INSERT INTO " . $GLOBALS['prefix_lms'] . "_organization\n\t\t\t(idParent, path, lev, title,\n\t\t\tobjectType, idResource, idCategory, idUser, idAuthor,\n\t\t\tversion, difficult, description, language, resource,\n\t\t\tobjective, dateInsert, idCourse, prerequisites, isTerminator,\n\t\t\tidParam, visible, milestone)\n\t\t\tVALUES\n\t\t\t('" . (isset($map_org[$list_selmenun['idParent']]) ? $map_org[$list_selmenun['idParent']] : 0) . "', '" . $list_selmenun['path'] . "', '" . $list_selmenun['lev'] . "', '" . $list_selmenun['title'] . "',\n\t\t\t'" . $list_selmenun['objectType'] . "', '" . $id_nuovo_lo . "', '" . $list_selmenun['idCategory'] . "', '" . $list_selmenun['idUser'] . "', '" . $list_selmenun['idAuthor'] . "',\n\t\t\t'" . $list_selmenun['version'] . "', '" . $list_selmenun['difficult'] . "', '" . $list_selmenun['description'] . "', '" . $list_selmenun['language'] . "', '" . $list_selmenun['resource'] . "',\n\t\t\t'" . $list_selmenun['objective'] . "', '" . $list_selmenun['dateInsert'] . "', '" . $new_course_dup . "', '" . $list_selmenun['prerequisites'] . "', '" . $list_selmenun['isTerminator'] . "',\n\t\t\t'" . $list_selmenun['idParam'] . "', '" . $list_selmenun['visible'] . "', '" . $list_selmenun['milestone'] . "')"; $result_dupmen = sql_query($query_dupmen); $map_org[$id_vecchio] = sql_insert_id(); } } $query_cor = "SELECT *\n\tFROM " . $GLOBALS['prefix_lms'] . "_organization\n\tWHERE\n\tidCourse = '" . $new_course_dup . "'\n\tAND prerequisites !='' "; $result_cor = sql_query($query_cor); while ($list_cor = sql_fetch_array($result_cor)) { $id_orgup = $list_cor['prerequisites']; $arr_pre = explode(",", $id_orgup); for ($i = 0; $i < sizeof($arr_pre); $i++) { $arr_pre[$i] = str_replace(intval($arr_pre[$i]), $array_cor[intval($arr_pre[$i])], $arr_pre[$i]); } $query_updcor = "UPDATE " . $GLOBALS['prefix_lms'] . "_organization\n\t\t\tSET prerequisites = '"; for ($i = 0; $i < sizeof($arr_pre); $i++) { if ($i != 0) { $query_updcor .= ","; } $query_updcor .= $arr_pre[$i]; } $query_updcor .= "' WHERE idOrg = '" . $list_cor['idOrg'] . "' "; $result_upcor = sql_query($query_updcor); } $query_selmenun = "SELECT * FROM\n\t" . $GLOBALS['prefix_lms'] . "_forum\n\tWHERE idCourse = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($list_selmenun = sql_fetch_array($result_selmenun)) { $query_dupmen = "INSERT INTO\n\t\t" . $GLOBALS['prefix_lms'] . "_forum\n\t\t(idCourse, title, description, locked, sequence, emoticons)\n\t\tVALUES\n\t\t('" . $new_course_dup . "', '" . $list_selmenun['title'] . "', '" . $list_selmenun['description'] . "',\n\t\t'" . $list_selmenun['locked'] . "', '" . $list_selmenun['sequence'] . "', '" . $list_selmenun['emoticons'] . "')"; $result_dupmen = sql_query($query_dupmen); } $query_selmenun = "SELECT * FROM\n\t" . $GLOBALS['prefix_lms'] . "_coursereport\n\tWHERE id_course = '" . $id_dupcourse . "' "; $sql2 = $query_selmenun; $result_selmenun = sql_query($query_selmenun); while ($list_selmenun = sql_fetch_array($result_selmenun)) { if (!isset($array_organization[$list_selmenun['id_source']]) or $array_organization[$list_selmenun['id_source']] == "") { $array_organization[$list_selmenun['id_source']] = 0; } $query_dupmen = "INSERT INTO\n\t\t" . $GLOBALS['prefix_lms'] . "_coursereport\n\t\t(id_course,title,max_score,required_score,weight,show_to_user,use_for_final,sequence,source_of,id_source)\n\t\tVALUES\n\t\t('" . $new_course_dup . "', '" . $list_selmenun['title'] . "', '" . $list_selmenun['max_score'] . "',\n\t\t'" . $list_selmenun['required_score'] . "', '" . $list_selmenun['weight'] . "', '" . $list_selmenun['show_to_user'] . "', '" . $list_selmenun['use_for_final'] . "', '" . $list_selmenun['sequence'] . "', '" . $list_selmenun['source_of'] . "', '" . $array_organization[$list_selmenun['id_source']] . "')"; $sql2 = $query_dupmen; $result_dupmen = sql_query($query_dupmen); } $query_selmenun = "SELECT *\n\tFROM " . $GLOBALS['prefix_lms'] . "_htmlfront\n\tWHERE id_course = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($list_selmenun = sql_fetch_array($result_selmenun)) { $query_dupmen = "INSERT INTO " . $GLOBALS['prefix_lms'] . "_htmlfront\n\t\t(id_course, textof)\n\t\tVALUES\n\t\t('" . $new_course_dup . "', '" . mysql_escape_string($list_selmenun['textof']) . "')"; $result_dupmen = sql_query($query_dupmen); } //Util::jump_to('index.php?modname=course&op=course_list&result=ok_course'); return true; }
public function dupcourse() { if (!$this->permissions['add']) { $output = array('success' => false, 'message' => $this->_getMessage("no permission")); echo $this->json->encode($output); return; } //TO DO: make it a sqltransaction if possible if (isset($_POST['confirm'])) { $id_dupcourse = Get::req('id_course', DOTY_INT, 0); $id_orgs = array(); $array_new_testobject = array(); // read the old course info $query_sel = "SELECT * FROM %lms_course WHERE idCourse = '" . $id_dupcourse . "' "; $result_sel = sql_query($query_sel); $list_sel = sql_fetch_array($result_sel); foreach ($list_sel as $k => $v) { $list_sel[$k] = sql_escape_string($v); } $new_course_dup = 0; $new_file_array = array(); if ($list_sel['imgSponsor'] != '') { $new_name_array = explode('_', str_replace('course_sponsor_logo_', '', $list_sel['imgSponsor'])); $filename = 'course_sponsor_logo_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_sponsor_logo_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['imgSponsor']); $new_file_array[0]['old'] = $list_sel['imgSponsor']; $new_file_array[0]['new'] = $filename; $list_sel['imgSponsor'] = $filename; } if ($list_sel['img_course'] != '') { $new_name_array = explode('_', str_replace('course_logo_', '', $list_sel['img_course'])); $filename = 'course_logo_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_logo_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['img_course']); $new_file_array[1]['old'] = $list_sel['img_course']; $new_file_array[1]['new'] = $filename; $list_sel['img_course'] = $filename; } if ($list_sel['img_material'] != '') { $new_name_array = explode('_', str_replace('course_user_material_', '', $list_sel['img_material'])); $filename = 'course_user_material_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_user_material_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['img_material']); $new_file_array[2]['old'] = $list_sel['img_material']; $new_file_array[2]['new'] = $filename; $list_sel['img_material'] = $filename; } if ($list_sel['img_othermaterial'] != '') { $new_name_array = explode('_', str_replace('course_otheruser_material_', '', $list_sel['img_othermaterial'])); $filename = 'course_otheruser_material_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_otheruser_material_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['img_othermaterial']); $new_file_array[3]['old'] = $list_sel['img_othermaterial']; $new_file_array[3]['new'] = $filename; $list_sel['img_othermaterial'] = $filename; } if ($list_sel['course_demo'] != '') { $new_name_array = explode('_', str_replace('course_demo_', '', $list_sel['course_demo'])); $filename = 'course_demo_' . mt_rand(0, 100) . '_' . time() . '_' . str_replace('course_demo_' . $new_name_array[0] . '_' . $new_name_array[1] . '_', '', $list_sel['course_demo']); $new_file_array[4]['old'] = $list_sel['course_demo']; $new_file_array[4]['new'] = $filename; $list_sel['course_demo'] = $filename; } // duplicate the entry of learning_course $query_ins = "INSERT INTO %lms_course\n\t\t\t\t( idCategory, code, name, description, lang_code, status, level_show_user,\n\t\t\t\tsubscribe_method, linkSponsor, imgSponsor, img_course, img_material, img_othermaterial,\n\t\t\t\tcourse_demo, mediumTime, permCloseLO, userStatusOp, difficult, show_progress, show_time, show_extra_info,\n\t\t\t\tshow_rules, valid_time, max_num_subscribe, min_num_subscribe,\n\t\t\t\tmax_sms_budget, selling, prize, course_type, policy_point, point_to_all, course_edition, classrooms, certificates,\n\t\t\t\tcreate_date, security_code, imported_from_connection, course_quota, used_space, course_vote, allow_overbooking, can_subscribe,\n\t\t\t\tsub_start_date, sub_end_date, advance, show_who_online, direct_play, autoregistration_code, use_logo_in_courselist )\n\t\t\t\tVALUES\n\t\t\t\t( '" . $list_sel['idCategory'] . "', '" . $list_sel['code'] . "', '" . "Copia di " . $list_sel['name'] . "', '" . $list_sel['description'] . "', '" . $list_sel['lang_code'] . "', '" . $list_sel['status'] . "', '" . $list_sel['level_show_user'] . "',\n\t\t\t\t'" . $list_sel['subscribe_method'] . "', '" . $list_sel['linkSponsor'] . "', '" . $list_sel['imgSponsor'] . "', '" . $list_sel['img_course'] . "', '" . $list_sel['img_material'] . "', '" . $list_sel['img_othermaterial'] . "',\n\t\t\t\t'" . $list_sel['course_demo'] . "', '" . $list_sel['mediumTime'] . "', '" . $list_sel['permCloseLO'] . "', '" . $list_sel['userStatusOp'] . "', '" . $list_sel['difficult'] . "', '" . $list_sel['show_progress'] . "', '" . $list_sel['show_time'] . "', '" . $list_sel['show_extra_info'] . "',\n\t\t\t\t'" . $list_sel['show_rules'] . "', '" . $list_sel['valid_time'] . "', '" . $list_sel['max_num_subscribe'] . "', '" . $list_sel['min_num_subscribe'] . "',\n\t\t\t\t'" . $list_sel['max_sms_budget'] . "', '" . $list_sel['selling'] . "', '" . $list_sel['prize'] . "', '" . $list_sel['course_type'] . "', '" . $list_sel['policy_point'] . "', '" . $list_sel['point_to_all'] . "', '" . $list_sel['course_edition'] . "', '" . $list_sel['classrooms'] . "', '" . $list_sel['certificates'] . "',\n\t\t\t\t'" . date('Y-m-d H:i:s') . "', '" . $list_sel['security_code'] . "', '" . $list_sel['imported_from_connection'] . "', '" . $list_sel['course_quota'] . "', '" . $list_sel['used_space'] . "', '" . $list_sel['course_vote'] . "', '" . $list_sel['allow_overbooking'] . "', '" . $list_sel['can_subscribe'] . "',\n\t\t\t\t'" . $list_sel['sub_start_date'] . "', '" . $list_sel['sub_end_date'] . "', '" . $list_sel['advance'] . "', '" . $list_sel['show_who_online'] . "', '" . $list_sel['direct_play'] . "', '" . $list_sel['autoregistration_code'] . "', '" . $list_sel['use_logo_in_courselist'] . "' )"; $result_ins = sql_query($query_ins); if (!$result_ins) { ob_clean(); ob_start(); echo $this->json->encode(array('success' => false)); die; } // the id of the new course created $new_id_course = $new_course_dup = sql_insert_id(); //Create the new course file if (isset($_POST['image'])) { $path = Get::sett('pathcourse'); $path = '/appLms/' . Get::sett('pathcourse') . (substr($path, -1) != '/' && substr($path, -1) != '\\' ? '/' : ''); require_once _base_ . '/lib/lib.upload.php'; sl_open_fileoperations(); foreach ($new_file_array as $file_info) { sl_copy($path . $file_info['old'], $path . $file_info['new']); } sl_close_fileoperations(); } //--- copy menu data ----------------------------------------------------- // copy the old course menu into the new one $query_selmen = "SELECT * FROM %lms_menucourse_main WHERE idCourse = '" . $id_dupcourse . "' "; $result_selmen = sql_query($query_selmen); while ($list_selmen = sql_fetch_array($result_selmen)) { $query_dupmen = "INSERT INTO %lms_menucourse_main " . " (idCourse, sequence, name, image) " . " VALUES " . " ( '" . $new_course_dup . "', '" . $list_selmen['sequence'] . "', '" . $list_selmen['name'] . "', '" . $list_selmen['image'] . "' )"; $result_dupmen = sql_query($query_dupmen); $array_seq[$list_selmen['idMain']] = sql_insert_id(); } $query_insert_list = array(); $query_selmenun = "SELECT * FROM %lms_menucourse_under WHERE idCourse = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($new_org = sql_fetch_array($result_selmenun)) { $valore_idn = $new_org['idMain']; $_idMain = $array_seq[$valore_idn]; $query_insert_list[] = "('" . $_idMain . "', '" . $new_course_dup . "', '" . $new_org['sequence'] . "', '" . $new_org['idModule'] . "', '" . $new_org['my_name'] . "')"; } $result_dupmen = true; if (!empty($query_insert_list)) { $query_dupmen = "INSERT INTO %lms_menucourse_under\n\t\t\t\t\t(idMain, idCourse, sequence, idModule, my_name)\n\t\t\t\t\tVALUES " . implode(",", $query_insert_list); $result_dupmen = sql_query($query_dupmen); } //--- end menu ----------------------------------------------------------- function &getCourseLevelSt($id_course) { $map = array(); $levels = CourseLevel::getLevels(); // find all the group created for this menu custom for permission management foreach ($levels as $lv => $name_level) { $group_info = Docebo::aclm()->getGroup(FALSE, '/lms/course/' . $id_course . '/subscribed/' . $lv); $map[$lv] = $group_info[ACL_INFO_IDST]; } return $map; } function funAccess($functionname, $mode, $returnValue = false, $custom_mod_name = false) { return true; } require_once _lms_ . '/lib/lib.course.php'; require_once _lms_ . '/lib/lib.manmenu.php'; require_once _lms_ . '/lib/lib.subscribe.php'; $docebo_course = new DoceboCourse($id_dupcourse); $subscribe_man = new CourseSubscribe_Manager(); $group_idst =& $docebo_course->createCourseLevel($new_course_dup); $group_of_from =& $docebo_course->getCourseLevel($id_dupcourse); $perm_form =& createPermForCoursebis($group_of_from, $new_course_dup, $id_dupcourse); $levels = $subscribe_man->getUserLevel(); foreach ($levels as $lv => $name_level) { foreach ($perm_form[$lv] as $idrole => $v) { if ($group_idst[$lv] != 0 && $idrole != 0) { Docebo::aclm()->addToRole($idrole, $group_idst[$lv]); } } } if (isset($_POST['certificate'])) { // duplicate the certificate assigned $query_insert_list = array(); $query_selmenun = "SELECT * FROM %lms_certificate_course WHERE id_course = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($new_org = sql_fetch_assoc($result_selmenun)) { $query_insert_list[] = "('" . $new_org['id_certificate'] . "', '" . $new_course_dup . "', \n\t\t\t\t\t\t'" . $new_org['available_for_status'] . "', '" . $new_org['point_required'] . "' )"; } $result_dupmen = true; if (!empty($query_insert_list)) { $query_dupmen = "INSERT INTO %lms_certificate_course\n\t\t\t\t\t\t(id_certificate, id_course, available_for_status, point_required)\n\t\t\t\t\t\tVALUES " . implode(",", $query_insert_list); $result_dupmen = sql_query($query_dupmen); } } require_once _lms_ . '/modules/organization/orglib.php'; require_once _lms_ . '/lib/lib.param.php'; require_once _lms_ . '/class.module/track.object.php'; require_once _lms_ . '/class.module/learning.object.php'; $nullVal = NULL; $id_orgs = array(); $map_org = array(); if (isset($_POST['lo'])) { $org_map = array(); $id_orgs = array(); $prereq_map = array(); // retrive all the folders and object, the order by grant that folder are created before the elements contained in them $query = "SELECT * FROM %lms_organization WHERE idCourse = " . (int) $id_dupcourse . " ORDER BY path ASC"; $source_res = sql_query($query); // Go trough all the entry of learning_organization while ($source = sql_fetch_object($source_res)) { // check if LO id is checked if (in_array($source->idOrg, $_POST['lo_list'])) { // if it's an object we must make a copy, if it's a folder we can create a row // inside learning_orgation and save the id for later use if ($source->objectType == '') { // is a folder // create a new row in learning_organization $query_new_org = "INSERT INTO %lms_organization (\n\t\t\t\t\t\t\t\tidParent,\n\t\t\t\t\t\t\t\tpath, lev, title,\n\t\t\t\t\t\t\t\tobjectType, idResource, idCategory, idUser,\n\t\t\t\t\t\t\t\tidAuthor, version, difficult, description,\n\t\t\t\t\t\t\t\tlanguage, resource, objective, dateInsert,\n\t\t\t\t\t\t\t\tidCourse, prerequisites, isTerminator, idParam,\n\t\t\t\t\t\t\t\tvisible, milestone)\n\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t('" . (isset($id_orgs[$source->idParent]) ? $id_orgs[$source->idParent] : 0) . "',\n\t\t\t\t\t\t\t\t'" . $source->path . "', '" . $source->lev . "', '" . sql_escape_string($source->title) . "',\n\t\t\t\t\t\t\t\t'" . $source->objectType . "', '" . $source->idResource . "', '" . $source->idCategory . "', '" . $source->idUser . "',\n\t\t\t\t\t\t\t\t'" . $source->idAuthor . "', '" . $source->version . "', '" . $source->difficult . "', '" . sql_escape_string($source->description) . "',\n\t\t\t\t\t\t\t\t'" . $source->language . "', '" . $source->resource . "', '" . $source->objective . "', '" . $source->dateInsert . "',\n\t\t\t\t\t\t\t\t'" . $new_id_course . "', '" . $source->prerequisites . "', '" . $source->isTerminator . "', '" . $source->idParam . "',\n\t\t\t\t\t\t\t\t'" . $source->visible . "', '" . $source->milestone . "')"; $re_new_org = sql_query($query_new_org); $new_id_reference = sql_insert_id(); // map for later use $org_map['folder'][$source->idOrg] = $new_id_reference; } else { // is an object // make a copy $lo = $this->_createLO($source->objectType); $new_id_resource = $lo->copy($source->idResource); // create a new row in learning_organization $query_new_org = "INSERT INTO %lms_organization (\n\t\t\t\t\t\t\t\tidParent, path, lev, title,\n\t\t\t\t\t\t\t\tobjectType, idResource, idCategory, idUser,\n\t\t\t\t\t\t\t\tidAuthor, version, difficult, description,\n\t\t\t\t\t\t\t\tlanguage, resource, objective, dateInsert,\n\t\t\t\t\t\t\t\tidCourse, prerequisites, isTerminator, idParam,\n\t\t\t\t\t\t\t\tvisible, milestone)\n\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t('" . (isset($id_orgs[$source->idParent]) ? $id_orgs[$source->idParent] : 0) . "',\n\t\t\t\t\t\t\t\t'" . $source->path . "', '" . $source->lev . "', '" . sql_escape_string($source->title) . "',\n\t\t\t\t\t\t\t\t'" . $source->objectType . "', '" . $new_id_resource . "', '" . $source->idCategory . "', '" . $source->idUser . "',\n\t\t\t\t\t\t\t\t'" . $source->idAuthor . "', '" . $source->version . "', '" . $source->difficult . "', '" . sql_escape_string($source->description) . "',\n\t\t\t\t\t\t\t\t'" . $source->language . "', '" . $source->resource . "', '" . $source->objective . "', '" . $source->dateInsert . "',\n\t\t\t\t\t\t\t\t'" . $new_id_course . "', '" . $source->prerequisites . "', '" . $source->isTerminator . "', '0',\n\t\t\t\t\t\t\t\t'" . $source->visible . "', '" . $source->milestone . "')"; $re_new_org = sql_query($query_new_org); $new_id_reference = sql_insert_id(); // for a learning_object we have to create a row in lo_param as well // with 4.1 or 4.2 we plan to remove this table, but until then we need this $query_lo_par = "INSERT INTO %lms_lo_param (param_name, param_value) VALUES ('idReference', '" . $new_id_reference . "') "; $result_lo_par = sql_query($query_lo_par); $id_lo_par = sql_insert_id(); $query_up_lo = "UPDATE %lms_lo_param SET idParam = '" . $id_lo_par . "' WHERE id = '" . $id_lo_par . "' "; $result_up_lo = sql_query($query_up_lo); $query_up_or = "UPDATE %lms_organization SET idParam = '" . $id_lo_par . "' WHERE idOrg = '" . $new_id_reference . "' "; $result_up_or = sql_query($query_up_or); // map for later use $org_map[$source->objectType][$source->idResource] = $new_id_resource; } // create a map for the olds and new idReferences $id_orgs[$source->idOrg] = $new_id_reference; if ($source->prerequisites != '') { $prereq_map[$new_id_reference] = $source->prerequisites; } } } // updates prerequisites foreach ($prereq_map as $new_id_reference => $old_prerequisites) { $new_prerequisites = array(); $old_prerequisites = explode(",", $old_prerequisites); foreach ($old_prerequisites as $old_p) { //a prerequisite can be a pure number or something like 7=NULL, or 7=incomplete $old_id = intval($old_p); if (isset($id_orgs[$old_id])) { $new_prerequisites[] = str_replace($old_id, $id_orgs[$old_id], $old_p); } } if (!empty($new_prerequisites)) { $query_updcor = "UPDATE %lms_organization " . "SET prerequisites = '" . implode(",", $new_prerequisites) . "' " . "WHERE idOrg = " . $new_id_reference . " "; $result_upcor = sql_query($query_updcor); } } //--- copy forum data -------------------------------------------------- $query_insert_list = array(); $query_selmenun = "SELECT * FROM %lms_forum WHERE idCourse = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($new_org = sql_fetch_assoc($result_selmenun)) { $query_insert_list[] = "('" . $new_course_dup . "', '" . sql_escape_string($new_org['title']) . "', '" . sql_escape_string($new_org['description']) . "',\n\t\t\t\t\t\t'" . $new_org['locked'] . "', '" . $new_org['sequence'] . "', '" . $new_org['emoticons'] . "')"; } $result_dupmen = true; if (!empty($query_insert_list)) { $query_dupmen = "INSERT INTO %lms_forum\n\t\t\t\t\t\t(idCourse, title, description, locked, sequence, emoticons)\n\t\t\t\t\t\tVALUES " . implode(",", $query_insert_list); $result_dupmen = sql_query($query_dupmen); } //--- end forum -------------------------------------------------------- //--- copy coursereports data ------------------------------------------ //create a conversion table for tests and scoitems coursereports $array_organization = array('test' => array(), 'scoitem' => array()); $arr_items_flat = array('test' => array(), 'scoitem' => array()); $query_org = "SELECT source_of, id_source\n\t\t\t\t\tFROM %lms_coursereport WHERE id_course = '" . $id_dupcourse . "'\n\t\t\t\t\tAND source_of IN ('test', 'scoitem')"; $res_org = sql_query($query_org); while (list($source_of, $id_source) = sql_fetch_row($res_org)) { switch ($source_of) { case 'scoitem': $arr_items_flat['scoitem'][] = $id_source; break; } } if (!empty($arr_items_flat['scoitem'])) { //retrieve idOrgs of scoitems' scormorgs $arr_old_idorg = array(); $arr_old_ident = array(); $query = "SELECT o.idOrg, o.idResource, s.idscorm_item, s.item_identifier\n\t\t\t\t\t\tFROM %lms_organization AS o\n\t\t\t\t\t\tJOIN %lms_scorm_items AS s\n\t\t\t\t\t\tON (o.idResource = s.idscorm_organization)\n\t\t\t\t\t\tWHERE s.idscorm_item IN (" . implode(",", $arr_items_flat['scoitem']) . ")\n\t\t\t\t\t\tAND o.objectType = 'scormorg'"; $res = sql_query($query); while (list($idOrg, $idResource, $idscorm_item, $item_identifier) = sql_fetch_row($res)) { $arr_old_idorg[] = $idOrg; $arr_old_ident[$idOrg . '/' . $item_identifier] = $idscorm_item; } if (!empty($arr_old_idorg)) { $arr_new_idorg = array(); foreach ($arr_old_idorg as $idOrg) { $arr_new_idorg[] = $id_orgs[$idOrg]; } $query = "SELECT o.idOrg, o.idResource, s.idscorm_item, s.item_identifier\n\t\t\t\t\t\t\tFROM %lms_organization AS o\n\t\t\t\t\t\t\tJOIN %lms_scorm_items AS s\n\t\t\t\t\t\t\tON (o.idResource = s.idscorm_organization)\n\t\t\t\t\t\t\tWHERE o.idOrg IN (" . implode(",", $arr_new_idorg) . ")\n\t\t\t\t\t\t\tAND o.objectType = 'scormorg'"; $res = sql_query($query); $new_to_old = array_flip($id_orgs); while (list($idOrg, $idResource, $idscorm_item, $item_identifier) = sql_fetch_row($res)) { $_key = $new_to_old[$idOrg] . '/' . $item_identifier; if (array_key_exists($_key, $arr_old_ident)) { $_index = $arr_old_ident[$_key]; $array_organization['scoitem'][$_index] = $idscorm_item; } } } } $query_insert_list = array(); $query_selmenun = "SELECT * FROM %lms_coursereport WHERE id_course = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($new_org = sql_fetch_array($result_selmenun)) { $id_source_val = 0; switch ($new_org['source_of']) { case 'test': $id_source_val = !isset($org_map['test'][$new_org['id_source']]) ? 0 : $org_map['test'][$new_org['id_source']]; break; case 'scoitem': $id_source_val = !isset($array_organization['scoitem'][$new_org['id_source']]) || $array_organization['scoitem'][$new_org['id_source']] == "" ? 0 : $array_organization['scoitem'][$new_org['id_source']]; break; } $query_insert_list[] = "('" . $new_course_dup . "', '" . sql_escape_string($new_org['title']) . "', '" . $new_org['max_score'] . "',\n\t\t\t\t\t\t'" . $new_org['required_score'] . "', '" . $new_org['weight'] . "', '" . $new_org['show_to_user'] . "',\n\t\t\t\t\t\t'" . $new_org['use_for_final'] . "', '" . $new_org['sequence'] . "', '" . $new_org['source_of'] . "',\n\t\t\t\t\t\t'" . $id_source_val . "')"; } $result_dupman = true; if (!empty($query_insert_list)) { $query_dupmen = "INSERT INTO %lms_coursereport\n\t\t\t\t\t\t(id_course,title,max_score,required_score,weight,show_to_user,use_for_final,sequence,source_of,id_source)\n\t\t\t\t\t\tVALUES " . implode(",", $query_insert_list); $result_dupmen = sql_query($query_dupmen); } //--- end coursereports ------------------------------------------------ //--- copy htmlfront data ---------------------------------------------- $query_insert_list = array(); $query_selmenun = "SELECT * FROM %lms_htmlfront WHERE id_course = '" . $id_dupcourse . "' "; $result_selmenun = sql_query($query_selmenun); while ($new_org = sql_fetch_array($result_selmenun)) { $query_insert_list[] = "('" . $new_course_dup . "', '" . sql_escape_string($new_org['textof']) . "')"; } $result_dupmen = true; if (!empty($query_insert_list)) { $query_dupmen = "INSERT INTO %lms_htmlfront\n\t\t\t\t\t\t(id_course, textof)\n\t\t\t\t\t\tVALUES " . implode(",", $query_insert_list); $result_dupmen = sql_query($query_dupmen); } //--- end htmlfront ---------------------------------------------------- } if (isset($_POST['advice'])) { $query = "SELECT * FROM %lms_advice WHERE idCourse = " . (int) $id_dupcourse; $result = sql_query($query); if (sql_num_rows($result) > 0) { $query_insert_list = array(); $array_sub = array(); $array_replace = array(); foreach ($id_orgs as $id_old_obj => $id_new_obj) { $array_sub[] = 'id_org=' . $id_old_obj; $array_replace[] = 'id_org=' . $id_new_obj; //convert direct links to LOs. TO DO: make sure you are changing only the correct link urls $array_sub[] = 'id_item=' . $id_old_obj; $array_replace[] = 'id_item=' . $id_new_obj; } while ($row = sql_fetch_assoc($result)) { $new_description = !empty($id_orgs) ? str_replace($array_sub, $array_replace, $row['description']) : $row['description']; $query_insert_list[] = "(NULL, " . (int) $new_course_dup . ", '" . $row['posted'] . "', " . (int) $row['author'] . ", '" . $row['title'] . "', '" . $new_description . "', " . (int) $row['important'] . ")"; } if (!empty($query_insert_list)) { $query = "INSERT INTO %lms_advice\n\t\t\t\t\t\t\t(idAdvice, idCourse, posted, author, title, description, important)\n\t\t\t\t\t\t\tVALUES " . implode(",", $query_insert_list); sql_query($query); } } } ob_clean(); echo $this->json->encode(array('success' => true)); } }