123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936 |
- <?php
- require_once 'aiccItem.class.php';
- require_once 'aiccResource.class.php';
- require_once 'aiccBlock.class.php';
- class aicc extends learnpath {
- public $config = array();
- public $config_basename = '';
-
-
- public $config_files = array();
- public $config_exts = array(
- 'crs' => 0,
- 'au' => 0,
- 'des' => 0,
- 'cst' => 0,
- 'ore' => 0,
- 'pre' => 0,
- 'cmp' => 0
- );
- public $aulist = array();
- public $au_order_list = array();
- public $au_order_list_new_id = array();
- public $deslist = array();
- public $cstlist = array();
- public $orelist = array();
- public $subdir = '';
- public $zipname = '';
- public $lastzipnameindex = 0;
- public $config_encoding = 'ISO-8859-1';
- public $debug = 0;
-
- public function __construct($course_code = null, $resource_id = null, $user_id = null) {
- if ($this->debug > 0) { error_log('In aicc::aicc()', 0); }
- if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) {
- parent::__construct($course_code, $resource_id, $user_id);
- } else {
-
- }
- }
-
- public function open($id) {
- if ($this->debug > 0) { error_log('In aicc::open()', 0); }
-
- }
-
- function parse_config_files($dir = '') {
- if ($this->debug > 0) {error_log('New LP - In aicc::parse_config_files('.$dir.')', 0); }
- if (empty($dir)) {
-
- $dir = $this->subdir;
- }
- if (is_dir($dir) && is_readable($dir)) {
-
-
-
- $crs_file = $dir.'/'.$this->config_files['crs'];
- $crs_params = $this->parse_ini_file_quotes_safe($crs_file);
-
- if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$crs_file.' has been parsed', 0); }
-
- if (!empty($crs_params['course']['course_creator'])) {
- $this->course_creator = Database::escape_string($crs_params['course']['course_creator']);
- }
- if (!empty($crs_params['course']['course_id'])) {
- $this->course_id = Database::escape_string($crs_params['course']['course_id']);
- }
- if (!empty($crs_params['course']['course_system'])) {
- $this->course_system = $crs_params['course']['course_system'];
- }
- if (!empty($crs_params['course']['course_title'])) {
- $this->course_title = Database::escape_string($crs_params['course']['course_title']);
- }
- if (!empty($crs_params['course']['course_level'])) {
- $this->course_level = $crs_params['course']['course_level'];
- }
- if (!empty($crs_params['course']['max_fields_cst'])) {
- $this->course_max_fields_cst = $crs_params['course']['max_fields_cst'];
- }
- if (!empty($crs_params['course']['max_fields_ort'])) {
- $this->course_max_fields_ort = $crs_params['course']['max_fields_ort'];
- }
- if (!empty($crs_params['course']['total_aus'])) {
- $this->course_total_aus = $crs_params['course']['total_aus'];
- }
- if (!empty($crs_params['course']['total_blocks'])) {
- $this->course_total_blocks = $crs_params['course']['total_blocks'];
- }
- if (!empty($crs_params['course']['total_objectives'])) {
- $this->course_total_objectives = $crs_params['course']['total_objectives'];
- }
- if (!empty($crs_params['course']['total_complex_objectives'])) {
- $this->course_total_complex_objectives = $crs_params['course']['total_complex_objectives'];
- }
- if (!empty($crs_params['course']['version'])) {
- $this->course_version = $crs_params['course']['version'];
- }
- if (!empty($crs_params['course_description'])) {
- $this->course_description = Database::escape_string($crs_params['course_description']);
- }
-
- $des_file = $dir.'/'.$this->config_files['des'];
- $des_params = $this->parse_csv_file($des_file);
-
- if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$des_file.' has been parsed', 0); }
-
- foreach ($des_params as $des){
-
- $oDes = new aiccResource('config', $des);
- $this->deslist[$oDes->identifier] = $oDes;
- }
-
- $au_file = $dir.'/'.$this->config_files['au'];
- $au_params = $this->parse_csv_file($au_file);
-
- if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$au_file.' has been parsed', 0); }
-
- foreach ($au_params as $au) {
- $oAu = new aiccItem('config', $au);
- $this->aulist[$oAu->identifier] = $oAu;
- $this->au_order_list[] = $oAu->identifier;
- }
-
- $cst_file = $dir.'/'.$this->config_files['cst'];
- $cst_params = $this->parse_csv_file($cst_file, ',', '"', true);
-
- if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$cst_file.' has been parsed', 0); }
-
- foreach ($cst_params as $cst) {
- $oCst = new aiccBlock('config', $cst);
- $this->cstlist[$oCst->identifier] = $oCst;
- }
-
-
- if (!empty($this->config_files['ore'])) {
- $ore_file = $dir.'/'.$this->config_files['ore'];
- $ore_params = $this->parse_csv_file($ore_file, ',', '"', true);
-
- if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$ore_file.' has been parsed', 0); }
-
- foreach ($ore_params as $ore) {
- $oOre = new aiccObjective('config', $ore);
- $this->orelist[$oOre->identifier] = $oOre;
- }
- }
-
- if (!empty($this->config_files['pre'])) {
- $pre_file = $dir.'/'.$this->config_files['pre'];
- $pre_params = $this->parse_csv_file($pre_file);
-
- if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$pre_file.' has been parsed', 0); }
-
- foreach ($pre_params as $pre) {
-
- if (in_array(api_strtolower($pre['structure_element']), array_keys($this->cstlist))) {
-
- $this->cstlist[api_strtolower($pre['structure_element'])]->prereq_string = api_strtolower($pre['prerequisite']);
- }
- if (in_array(api_strtolower($pre['structure_element']), array_keys($this->aulist))) {
-
- $this->aulist[api_strtolower($pre['structure_element'])]->prereq_string = api_strtolower($pre['prerequisite']);
- }
- }
- }
-
-
- if (!empty($this->config_files['cmp'])) {
- $cmp_file = $dir.'/'.$this->config_files['cmp'];
- $cmp_params = $this->parse_csv_file($cmp_file);
-
- if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$cmp_file.' has been parsed', 0); }
-
- foreach ($cmp_params as $cmp) {
-
-
- }
- }
- }
- return $this->config;
- }
-
- function import_aicc($course_code) {
- if ($this->debug > 0) { error_log('New LP - In aicc::import_aicc('.$course_code.')', 0); }
-
- $new_lp = 'lp';
- $new_lp_item = 'lp_item';
-
- $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE code='$course_code'";
- $res = Database::query($sql);
- if (Database::num_rows($res) < 1) { error_log('New LP - Database for '.$course_code.' not found '.__FILE__.' '.__LINE__, 0); return -1; }
- $row = Database::fetch_array($res);
-
- $new_lp = Database::get_course_table(TABLE_LP_MAIN);
- $new_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $get_max = "SELECT MAX(display_order) FROM $new_lp";
- $res_max = Database::query($get_max);
- if (Database::num_rows($res_max) < 1) {
- $dsp = 1;
- } else {
- $row = Database::fetch_array($res_max);
- $dsp = $row[0] + 1;
- }
- $this->config_encoding = "ISO-8859-1";
- $sql = "INSERT INTO $new_lp (c_id, lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib, content_maker,display_order)" .
- "VALUES " .
- "($this->course_id, 3, '".$this->course_title."', '".$this->course_id."','".$this->course_description."'," .
- "'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."'," .
- "'aicc_api.php','".$this->course_creator."',$dsp)";
- if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: '. $sql, 0); }
- $res = Database::query($sql);
- $lp_id = Database::insert_id();
- $this->lp_id = $lp_id;
- api_item_property_update(api_get_course_info($course_code), TOOL_LEARNPATH, $this->lp_id, 'LearnpathAdded', api_get_user_id());
- api_item_property_update(api_get_course_info($course_code), TOOL_LEARNPATH, $this->lp_id, 'visible', api_get_user_id());
- $previous = 0;
- foreach ($this->aulist as $identifier => $dummy) {
- $oAu =& $this->aulist[$identifier];
-
- $field_add = '';
- $value_add = '';
- if (!empty($oAu->masteryscore)) {
- $field_add = 'mastery_score, ';
- $value_add = $oAu->masteryscore.',';
- }
- $title = $oAu->identifier;
- if (is_object($this->deslist[$identifier])) {
- $title = $this->deslist[$identifier]->title;
- }
- $path = $oAu->path;
-
-
- $parent = 0;
- $previous = 0;
- $prereq = $oAu->prereq_string;
-
- $sql_item = "INSERT INTO $new_lp_item (c_id, lp_id,item_type,ref,title, path,min_score,max_score, $field_add parent_item_id,previous_item_id,next_item_id, prerequisite,display_order) " .
- "VALUES " .
- "($this->course_id, $lp_id, 'au','".$oAu->identifier."','".$title."'," .
- "'$path',0,100, $value_add" .
- "$parent, $previous, 0, " .
- "'$prereq', 0" .
- ")";
- $res_item = Database::query($sql_item);
- if ($this->debug > 1) { error_log('New LP - In aicc::import_aicc() - inserting item : '.$sql_item.' : '.Database::error(), 0); }
- $item_id = Database::insert_id();
-
- if ($previous != 0) {
- $upd = "UPDATE $new_lp_item SET next_item_id = $item_id WHERE id = $previous";
- $upd_res = Database::query($upd);
-
- }
- $previous = $item_id;
- }
- }
-
- function import_local_package($file_path, $current_dir = '') {
-
- $file_info = array();
- $file_info['tmp_name'] = $file_path;
- $file_info['name'] = basename($file_path);
-
- return $this->import_package($file_info, $current_dir);
- }
-
- function import_package($zip_file_info, $current_dir = '') {
- if ($this->debug > 0) { error_log('In aicc::import_package('.print_r($zip_file_info, true).',"'.$current_dir.'") method', 0); }
-
- $maxFilledSpace = 1000000000;
- $zip_file_path = $zip_file_info['tmp_name'];
- $zip_file_name = $zip_file_info['name'];
- if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Zip file path = '.$zip_file_path.', zip file name = '.$zip_file_name, 0); }
- $course_rel_dir = api_get_course_path().'/scorm';
- $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir;
- $current_dir = replace_dangerous_char(trim($current_dir), 'strict');
- if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Current_dir = '.$current_dir, 0); }
-
-
- if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Received zip file name: '.$zip_file_path, 0); }
- $file_info = pathinfo($zip_file_name);
- $filename = $file_info['basename'];
- $extension = $file_info['extension'];
- $file_base_name = str_replace('.'.$extension, '', $filename);
- $this->zipname = $file_base_name;
- if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Base file name is : '.$file_base_name, 0); }
- $new_dir = replace_dangerous_char(trim($file_base_name),'strict');
- $this->subdir = $new_dir;
- if($this->debug > 0) { error_log('New LP - aicc::import_package() - Subdir is first set to : '.$this->subdir, 0); }
-
- $zipFile = new pclZip($zip_file_path);
-
- $zipContentArray = $zipFile->listContent();
- $package_type = '';
- $package = '';
- $at_root = false;
- $config_dir = '';
- $files_found = array();
- $subdir_isset = false;
-
- foreach ($zipContentArray as $thisContent) {
- if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
-
- if ($this->debug > 1) {error_log('New LP - aicc::import_package() - Found unauthorized file: '.$thisContent['filename'], 0); }
- return api_failure::set_failure('php_file_in_zip_file');
- } elseif (preg_match('?.*/aicc/$?', $thisContent['filename'])) {
-
-
- if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Found aicc directory: '.$thisContent['filename'], 0); }
- $package_type = 'aicc';
- } else {
-
- $res = array();
- if (preg_match('?^(.*)\.(crs|au|des|cst|ore|pre|cmp)$?i', $thisContent['filename'], $res)) {
- if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Found AICC config file: '.$thisContent['filename'].'. Now splitting: '.$res[1].' and '.$res[2], 0); }
- if ($thisContent['filename'] == basename($thisContent['filename'])) {
- if ($this->debug > 2) { error_log('New LP - aicc::import_package() - '.$thisContent['filename'].' is at root level', 0); }
- $at_root = true;
- if (!is_array($files_found[$res[1]])) {
- $files_found[$res[1]] = $this->config_exts;
- }
- $files_found[$res[1]][api_strtolower($res[2])] = $thisContent['filename'];
- $subdir_isset = true;
- } else {
- if (!$subdir_isset) {
- if (preg_match('?^.*/aicc$?i',dirname($thisContent['filename']))) {
-
- $this->subdir .= '/'.substr(dirname($thisContent['filename']), 0, -5);
- } else {
-
- $this->subdir .= '/'.dirname($thisContent['filename']);
- }
- $subdir_isset = true;
- }
- if ($this->debug > 2) { error_log('New LP - aicc::import_package() - '.$thisContent['filename'].' is not at root level - recording subdir '.$this->subdir, 0); }
- $config_dir = dirname($thisContent['filename']);
- if (!is_array($files_found[basename($res[1])])) {
- $files_found[basename($res[1])] = $this->config_exts;
- }
- $files_found[basename($res[1])][api_strtolower($res[2])] = basename($thisContent['filename']);
- }
- $package_type = 'aicc';
- } else {
- if ($this->debug > 3) { error_log('New LP - aicc::import_package() - File '.$thisContent['filename'].' didnt match any check', 0); }
- }
- }
- $realFileSize += $thisContent['size'];
- }
- if ($this->debug > 2) { error_log('New LP - aicc::import_package() - $files_found: '.print_r($files_found, true), 0); }
- if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Package type is now '.$package_type, 0); }
- $mandatory = false;
- foreach ($files_found as $file_name => $file_exts) {
- $temp = (
- !empty($files_found[$file_name]['crs'])
- AND !empty($files_found[$file_name]['au'])
- AND !empty($files_found[$file_name]['des'])
- AND !empty($files_found[$file_name]['cst'])
- );
- if ($temp) {
- if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Found all config files for '.$file_name, 0); }
- $mandatory = true;
- $package = $file_name;
-
- $this->config_basename = $file_name;
-
- $this->config_files = $files_found[$file_name];
-
- break;
- }
- }
- if ($package_type == '' || !$mandatory)
-
- {
- return api_failure::set_failure('not_aicc_content');
- }
- if (!enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
- return api_failure::set_failure('not_enough_space');
- }
-
- if ($new_dir[0] != '/') {
- $new_dir = '/'.$new_dir;
- }
-
- if ($new_dir[strlen($new_dir) - 1] == '/') {
- $new_dir = substr($new_dir, 0, -1);
- }
-
-
- if (is_dir($course_sys_dir.$new_dir) OR @mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories())) {
-
- if ($this->debug >= 1) { error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir, 0); }
- $saved_dir = getcwd();
- chdir($course_sys_dir.$new_dir);
- $unzippingState = $zipFile->extract();
- for ($j = 0; $j < count($unzippingState); $j++) {
- $state = $unzippingState[$j];
-
- $extension = strrchr($state["stored_filename"], '.');
-
- }
- if (!empty($new_dir)) {
- $new_dir = $new_dir.'/';
- }
-
- if ($dir = @opendir($course_sys_dir.$new_dir)) {
- if ($this->debug == 1) { error_log('New LP - Opened dir '.$course_sys_dir.$new_dir, 0); }
- while ($file = readdir($dir)) {
- if ($file != '.' && $file != '..') {
- $filetype = 'file';
- if (is_dir($course_sys_dir.$new_dir.$file)) $filetype = 'folder';
-
-
- $find_str = array('\\', '.php', '.phtml');
- $repl_str = array('/', '.txt', '.txt');
- $safe_file = str_replace($find_str, $repl_str, $file);
- if ($safe_file != $file) {
-
- $mydir = dirname($course_sys_dir.$new_dir.$safe_file);
- if (!is_dir($mydir)) {
- $mysubdirs = split('/', $mydir);
- $mybasedir = '/';
- foreach ($mysubdirs as $mysubdir) {
- if (!empty($mysubdir)) {
- $mybasedir = $mybasedir.$mysubdir.'/';
- if (!is_dir($mybasedir)) {
- @mkdir($mybasedir, api_get_permissions_for_new_directories());
- if ($this->debug == 1) { error_log('New LP - Dir '.$mybasedir.' doesnt exist. Creating.', 0); }
- }
- }
- }
- }
- @rename($course_sys_dir.$new_dir.$file, $course_sys_dir.$new_dir.$safe_file);
- if ($this->debug == 1) { error_log('New LP - Renaming '.$course_sys_dir.$new_dir.$file.' to '.$course_sys_dir.$new_dir.$safe_file, 0); }
- }
-
- }
- }
- closedir($dir);
- chdir($saved_dir);
- }
- } else {
- return '';
- }
- return $course_sys_dir.$new_dir.$config_dir;
- }
-
- function set_proximity($proxy = '') {
- if ($this->debug > 0) { error_log('In aicc::set_proximity('.$proxy.') method', 0); }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET content_local = '$proxy' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- } else {
- return false;
- }
- }
-
- function set_theme($theme = '') {
- if ($this->debug > 0) { error_log('In aicc::set_theme('.$theme.') method', 0); }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET theme = '$theme' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- } else {
- return false;
- }
- }
-
- function set_preview_image($preview_image = '') {
- if ($this->debug > 0) {error_log('In aicc::set_preview_image('.$preview_image.') method', 0); }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET preview_image = '$preview_image' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- } else {
- return false;
- }
- }
-
- function set_author($author = '') {
- if ($this->debug > 0) { error_log('In aicc::set_author('.$author.') method', 0); }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET author = '$author' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- } else {
- return false;
- }
- }
-
- function set_maker($maker = '') {
- if ($this->debug > 0) { error_log('In aicc::set_maker method('.$maker.')', 0); }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET content_maker = '$maker' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- } else {
- return false;
- }
- }
-
- function export_zip($lp_id = null) {
- if ($this->debug > 0) { error_log('In aicc::export_zip method('.$lp_id.')', 0); }
- if (empty($lp_id)) {
- if (!is_object($this)) {
- return false;
- } else {
- $id = $this->get_id();
- if (empty($id)) {
- return false;
- } else {
- $lp_id = $this->get_id();
- }
- }
- }
-
-
-
- require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
- require_once api_get_path(LIBRARY_PATH).'document.lib.php';
- require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
- require_once 'learnpath_functions.inc.php';
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $_course = Database::get_course_info(api_get_course_id());
- $sql = "SELECT * FROM $tbl_lp WHERE id=".$lp_id;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $LPname = $row['path'];
- $list = split('/', $LPname);
- $LPnamesafe = $list[0];
-
-
- $zipfoldername = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/temp/'.$LPnamesafe;
- $scormfoldername = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/scorm/'.$LPnamesafe;
- $zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip';
-
-
- deldir($zipfoldername);
- mkdir($zipfoldername, api_get_permissions_for_new_directories());
-
-
- $zip_folder = new PclZip($zipfilename);
- $zip_folder->create($scormfoldername.'/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername.'/');
-
-
-
- DocumentManager :: file_send_for_download($zipfilename, true);
-
- my_delete($zipfilename);
- my_delete($zipfoldername);
- return true;
- }
-
- function get_res_path($id) {
- if ($this->debug > 0) { error_log('In aicc::get_res_path('.$id.') method', 0); }
- $path = '';
- if (isset($this->resources[$id])) {
- $oRes =& $this->resources[$id];
- $path = @$oRes->get_path();
- }
- return $path;
- }
-
- function get_res_type($id) {
- if ($this->debug > 0) { error_log('In aicc::get_res_type('.$id.') method', 0); }
- $type = '';
- if (isset($this->resources[$id])) {
- $oRes =& $this->resources[$id];
- $temptype = $oRes->get_scorm_type();
- if (!empty($temptype)) {
- $type = $temptype;
- }
- }
- return $type;
- }
-
- function get_title(){
- if ($this->debug > 0) { error_log('In aicc::get_title() method', 0); }
- $title = '';
- if (isset($this->config['organizations']['default'])) {
- $title = $this->organizations[$this->config['organizations']['default']]->get_name();
- } elseif (count($this->organizations) == 1) {
-
- foreach ($this->organizations as $id => $value) {
- $title = $this->organizations[$id]->get_name();
- break;
- }
- }
- return $title;
- }
-
- function reimport_aicc() {
- if ($this->debug > 0) { error_log('In aicc::reimport_aicc() method', 0); }
-
-
-
-
-
- return true;
- }
-
- function parse_ini_file_quotes_safe($f) {
- $null = '';
- $r = $null;
- $sec = $null;
- $f = @file_get_contents($f);
- $f = api_convert_encoding($f, api_get_system_encoding(), $this->config_encoding);
- $f = preg_split('/\r?\n/', $f);
- for ($i = 0; $i < @count($f); $i++) {
- $newsec = 0;
- $w = @trim($f[$i]);
- if ($w) {
- if ((!$r) or ($sec)) {
- if ((@substr($w, 0, 1) == '[') and (@substr($w, -1, 1)) == ']') {
- $sec = @substr($w, 1, @strlen($w) - 2);
- $newsec = 1;
- }
- }
- if (!$newsec) {
- $w = @explode('=', $w);
- $k = @trim($w[0]);
- unset($w[0]);
- $v = @trim(@implode('=', $w));
- if ((@substr($v, 0, 1) == "\"") and (@substr($v, -1, 1) == "\"")) {
- $v = @substr($v, 1, @strlen($v) - 2);
- }
- if ($sec) {
- if (api_strtolower($sec) == 'course_description') {
- $r[api_strtolower($sec)] = $k;
- } else {
- $r[api_strtolower($sec)][api_strtolower($k)] = $v;
- }
- } else {
- $r[api_strtolower($k)] = $v;
- }
- }
- }
- }
- return $r;
- }
-
- function parse_ini_string_quotes_safe($s, $pure_strings = array()) {
- $null = '';
- $r = $null;
- $sec = $null;
- $s = api_convert_encoding($s, api_get_system_encoding(), $this->config_encoding);
-
- $f = preg_split('/\r?\n/', $s);
- for ($i = 0; $i < @count($f); $i++) {
- $newsec = 0;
- $w = @trim($f[$i]);
- if ($w) {
- if ((!$r) or ($sec)) {
- if ((@substr($w, 0, 1) == '[') and (@substr($w, -1, 1)) == ']') {
- $sec = @substr($w, 1, @strlen($w) - 2);
- $pure_data = 0;
- if (in_array(api_strtolower($sec), $pure_strings)) {
-
- $pure_data = 1;
- $r[api_strtolower($sec)] = '';
- }
- $newsec = 1;
- }
- }
- if (!$newsec) {
- $w = @explode('=', $w);
- $k = @trim($w[0]);
- unset($w[0]);
- $v = @trim(@implode('=', $w));
- if ((@substr($v, 0, 1) == "\"") and (@substr($v, -1, 1) == "\"")) {
- $v = @substr($v, 1, @strlen($v) - 2);
- }
- if ($sec) {
- if ($pure_data) {
- $r[api_strtolower($sec)] .= $f[$i];
- } else {
- if (api_strtolower($sec) == 'course_description') {
- $r[api_strtolower($sec)] = $k;
- } else {
- $r[api_strtolower($sec)][api_strtolower($k)] = $v;
- }
- }
- } else {
- $r[api_strtolower($k)] = $v;
- }
- }
- }
- }
- return $r;
- }
-
- function parse_csv_file($f, $delim = ',', $enclosure = '"', $multiples = false) {
- $data = @file_get_contents($f);
- $data = api_convert_encoding($data, api_get_system_encoding(), $this->config_encoding);
- $enclosed = false;
- $fldcount = 0;
- $linecount = 0;
- $fldval = '';
- for ($i = 0; $i < strlen($data); $i++) {
- $chr = $data{$i};
- switch ($chr) {
- case $enclosure:
- if ($enclosed && $data{$i+1} == $enclosure) {
- $fldval .= $chr;
- ++$i;
- } else
- $enclosed = !$enclosed;
- break;
- case $delim:
- if (!$enclosed) {
- $ret_array[$linecount][$fldcount++] = $fldval;
- $fldval = '';
- } else
- $fldval .= $chr;
- break;
- case "\r":
- if (!$enclosed&&$data{$i+1} == "\n")
- continue;
- case "\n":
- if (!$enclosed) {
- $ret_array[$linecount++][$fldcount] = $fldval;
- $fldcount = 0;
- $fldval = '';
- } else
- $fldval .= $chr;
- break;
- case "\\r":
- if (!$enclosed&&$data{$i+1} == "\\n")
- continue;
- case "\\n":
- if (!$enclosed) {
- $ret_array[$linecount++][$fldcount] = $fldval;
- $fldcount = 0;
- $fldval = '';
- } else
- $fldval .= $chr;
- break;
- default:
- $fldval .= $chr;
- }
- }
- if ($fldval) {
- $ret_array[$linecount][$fldcount] = $fldval;
- }
-
- $titles = array();
- $ret_ret_array = array();
- foreach ($ret_array as $line_idx => $line) {
- if ($line_idx == 0) {
- $titles = $line;
- } else {
- $ret_ret_array[$line_idx] = array();
- foreach ($line as $idx => $val) {
- if ($multiples && !empty($ret_ret_array[$line_idx][api_strtolower($titles[$idx])])) {
- $ret_ret_array[$line_idx][api_strtolower($titles[$idx])] .= ','.$val;
- } else {
- $ret_ret_array[$line_idx][api_strtolower($titles[$idx])] = $val;
- }
- }
- }
- }
- return $ret_ret_array;
- }
- }
|