function getLastInsertID() { if ($this->hasError()) { return 0; } else { return claro_sql_insert_id(); } }
$thisLPMId = $_REQUEST['cmdid']; $sortDirection = "ASC"; break; case "createLabel": // create form sent if (isset($_REQUEST["newLabel"]) && trim($_REQUEST["newLabel"]) != "") { // determine the default order of this Learning path ( a new label is a root child) $sql = "SELECT MAX(`rank`)\n FROM `" . $TABLELEARNPATHMODULE . "`\n WHERE `parent` = 0"; $result = claro_sql_query($sql); list($orderMax) = mysql_fetch_row($result); $order = $orderMax + 1; // create new module $sql = "INSERT INTO `" . $TABLEMODULE . "`\n (`name`, `comment`, `contentType`, `launch_data`)\n VALUES ('" . claro_sql_escape($_POST['newLabel']) . "','', '" . CTLABEL_ . "', '')"; $query = claro_sql_query($sql); // request ID of the last inserted row (module_id in $TABLEMODULE) to add it in $TABLELEARNPATHMODULE $thisInsertedModuleId = claro_sql_insert_id(); // create new learning path module $sql = "INSERT INTO `" . $TABLELEARNPATHMODULE . "`\n (`learnPath_id`, `module_id`, `specificComment`, `rank`, `parent`)\n VALUES ('" . (int) $_SESSION['path_id'] . "', '" . (int) $thisInsertedModuleId . "','', " . (int) $order . ", 0)"; $query = claro_sql_query($sql); } else { $displayCreateLabelForm = true; // the form code comes after name and comment boxes section } break; default: break; } // change sorting if required if (isset($sortDirection) && $sortDirection) { // get list of modules with same parent as the moved module $sql = "SELECT LPM.`learnPath_module_id`, LPM.`rank`\n FROM (`" . $TABLELEARNPATHMODULE . "` AS LPM, `" . $TABLELEARNPATH . "` AS LP)\n LEFT JOIN `" . $TABLELEARNPATHMODULE . "` AS LPM2 ON LPM2.`parent` = LPM.`parent`\n WHERE LPM2.`learnPath_module_id` = " . (int) $thisLPMId . "\n AND LPM.`learnPath_id` = LP.`learnPath_id`\n AND LP.`learnPath_id` = " . (int) $_SESSION['path_id'] . "\n ORDER BY LPM.`rank` {$sortDirection}";
$sourceDoc = $baseWorkDir . $insertDocument; if (check_name_exist($sourceDoc)) { // check if a module of this course already used the same document $sql = "SELECT *\n FROM `" . $TABLEMODULE . "` AS M, `" . $TABLEASSET . "` AS A\n WHERE A.`module_id` = M.`module_id`\n AND {$modifier} A.`path` LIKE \"" . claro_sql_escape($insertDocument) . "\"\n AND M.`contentType` = \"" . CTDOCUMENT_ . "\""; $query = claro_sql_query($sql); $num = mysql_num_rows($query); $basename = substr($insertDocument, strrpos($insertDocument, '/') + 1); if ($num == 0) { // create new module $sql = "INSERT INTO `" . $TABLEMODULE . "`\n (`name` , `comment`, `contentType`, `launch_data`)\n VALUES ('" . claro_sql_escape($basename) . "' , '" . claro_sql_escape(get_block('blockDefaultModuleComment')) . "', '" . CTDOCUMENT_ . "', '' )"; $query = claro_sql_query($sql); $insertedModule_id = claro_sql_insert_id(); // create new asset $sql = "INSERT INTO `" . $TABLEASSET . "`\n (`path` , `module_id` , `comment`)\n VALUES ('" . claro_sql_escape($insertDocument) . "', " . (int) $insertedModule_id . ", '')"; $query = claro_sql_query($sql); $insertedAsset_id = claro_sql_insert_id(); $sql = "UPDATE `" . $TABLEMODULE . "`\n SET `startAsset_id` = " . (int) $insertedAsset_id . "\n WHERE `module_id` = " . (int) $insertedModule_id . ""; $query = claro_sql_query($sql); // determine the default order of this Learning path $sql = "SELECT MAX(`rank`)\n FROM `" . $TABLELEARNPATHMODULE . "`"; $result = claro_sql_query($sql); list($orderMax) = mysql_fetch_row($result); $order = $orderMax + 1; // finally : insert in learning path $sql = "INSERT INTO `" . $TABLELEARNPATHMODULE . "`\n (`learnPath_id`, `module_id`, `specificComment`, `rank`, `lock`)\n VALUES ('" . (int) $_SESSION['path_id'] . "', '" . (int) $insertedModule_id . "','" . claro_sql_escape(get_block('blockDefaultModuleAddedComment')) . "', " . (int) $order . ", 'OPEN')"; $query = claro_sql_query($sql); $dialogBox .= get_lang("%moduleName has been added as module", array('%moduleName' => $basename)) . '<br />' . "\n"; } else { // check if this is this LP that used this document as a module $sql = "SELECT *\n FROM `" . $TABLELEARNPATHMODULE . "` AS LPM,\n `" . $TABLEMODULE . "` AS M,\n `" . $TABLEASSET . "` AS A\n WHERE M.`module_id` = LPM.`module_id`\n AND M.`startAsset_id` = A.`asset_id`\n AND {$modifier} A.`path` = '" . claro_sql_escape($insertDocument) . "'\n AND LPM.`learnPath_id` = " . (int) $_SESSION['path_id']; $query2 = claro_sql_query($sql);
$errorFound = true; array_push($errorMsgs, get_lang('Error in SQL statement')); break; } // visibility if (isset($item['isvisible']) && $item['isvisible'] != '') { $item['isvisible'] == "true" ? $visibility = "SHOW" : ($visibility = "HIDE"); } else { $visibility = 'SHOW'; // IMS consider that the default value of 'isvisible' is true } // finally : insert in learning path $sql = "INSERT INTO `" . $TABLELEARNPATHMODULE . "`\n (`learnPath_id`, `module_id`, `specificComment`, `rank`, `visibility`, `lock`, `parent`)\n VALUES ('" . $tempPathId . "', '" . $insertedModule_id[$i] . "','" . claro_sql_escape(get_block('blockDefaultModuleAddedComment')) . "', " . $rank . ", '" . $visibility . "', 'OPEN', " . $parent . ")"; $query = claro_sql_query($sql); // get the inserted id of the learnPath_module rel to allow 'parent' link in next inserts $insertedLPMid[$item['itemIdentifier']]['LPMid'] = claro_sql_insert_id(); $insertedLPMid[$item['itemIdentifier']]['rank'] = 1; if (claro_sql_error()) { $errorFound = true; array_push($errorMsgs, get_lang('Error in SQL statement')); break; } if (!$errorFound) { array_push($okMsgs, get_lang('Module added : ') . "<i>" . $moduleName . "</i>"); } $i++; } //foreach } // if sizeof($manifestData['items'] == 0 ) }
/** * create the message in the message table and return the identification of this * * @return int message identification */ private final function addMessage($messageToSend) { //create an array of the name of the table needed $tableName = get_module_main_tbl(array('im_message')); $subject = claro_sql_escape($messageToSend->getSubject()); $message = claro_sql_escape($messageToSend->getMessage()); if (is_null($messageToSend->getSender())) { $sender = claro_get_current_user_id(); } else { $sender = (int) $messageToSend->getSender(); } if (!is_null($messageToSend->getCourseCode())) { $course = "'" . claro_sql_escape($messageToSend->getCourseCode()) . "'"; } else { $course = "NULL"; } if (!is_null($messageToSend->getGroupId())) { $group = (int) $messageToSend->getGroupId(); } else { $group = "NULL"; } if (!is_null($messageToSend->getToolsLabel())) { $tools = "'" . claro_sql_escape($messageToSend->getToolsLabel()) . "'"; } else { $tools = "NULL"; } // add the message in the table of messages and retrieves the ID $addInternalMessageSQL = "INSERT INTO `" . $tableName['im_message'] . "` \n" . "(sender, subject, message, send_time, course, `group` , tools) \n" . "VALUES ({$sender},'" . $subject . "','" . $message . "', '\n" . date("Y-m-d H:i:s", claro_time()) . "'," . $course . "," . $group . "," . $tools . ")\n"; // try to read the last ID inserted if the request pass if (claro_sql_query($addInternalMessageSQL)) { return claro_sql_insert_id(); } else { throw new Exception(claro_sql_errno() . ":" . claro_sql_error()); } }