/**
 * Import PDFs
 * @param   string  Filename
 * @param   string  The subdirectory in which to put the files in each course
 */
function import_pdfs($file, $subDir = '/')
{
    $baseDir = api_get_path(SYS_ARCHIVE_PATH);
    $uploadPath = 'pdfimport/';
    $errors = array();
    if (!is_dir($baseDir . $uploadPath)) {
        @mkdir($baseDir . $uploadPath);
    }
    if (!unzip_uploaded_file($_FILES['import_file'], $uploadPath, $baseDir, 1024 * 1024 * 1024)) {
        error_log('Could not unzip uploaded file in ' . __FILE__ . ', line ' . __LINE__);
        return $errors;
    }
    $list = scandir($baseDir . $uploadPath);
    $i = 0;
    foreach ($list as $file) {
        if (substr($file, 0, 1) == '.' or !is_file($baseDir . $uploadPath . $file)) {
            continue;
        }
        $parts = preg_split('/_/', $file);
        $course = api_get_course_info($parts[0]);
        if (count($course) > 0) {
            // Build file info because handle_uploaded_document() needs it (name, type, size, tmp_name)
            $fileSize = filesize($baseDir . $uploadPath . $file);
            $docId = add_document($course, $subDir . '/' . $file, 'file', $fileSize, $parts[1] . ' ' . substr($parts[2], 0, -4));
            if ($docId > 0) {
                if (!is_file($baseDir . $uploadPath . $file)) {
                    error_log($baseDir . $uploadPath . $file . ' does not exists in ' . __FILE__);
                }
                if (is_file(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file)) {
                    error_log(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file . ' exists at destination in ' . __FILE__);
                }
                if (!is_writeable(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir)) {
                    error_log('Destination ' . api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . ' is NOT writeable in ' . __FILE__);
                }
                // Place each file in its folder in each course
                $move = rename($baseDir . $uploadPath . $file, api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file);
                api_item_property_update($course, TOOL_DOCUMENT, $docId, 'DocumentAdded', api_get_user_id());
                // Redo visibility
                api_set_default_visibility($docId, TOOL_DOCUMENT);
                $errors[] = array('Line' => 0, 'Code' => $course['code'], 'Title' => $course['title']);
                // Now add a link to the file from the Course description tool
                $link = '<p>Sílabo de la asignatura <a href="' . api_get_path(WEB_CODE_PATH) . 'document/document.php?cidReq=' . $course['code'] . '&id_session=0&gidReq=0&action=download&id=' . $docId . '" target="_blank"><img src="' . api_get_path(WEB_IMG_PATH) . 'icons/32/pdf.png"></a></p>';
                $course_description = new CourseDescription();
                $session_id = api_get_session_id();
                $course_description->set_course_id($course['real_id']);
                $course_description->set_session_id($session_id);
                $course_description->set_title('Presentación de la asignatura');
                $course_description->set_content($link);
                $course_description->set_description_type(1);
                $course_description->insert();
            }
        } else {
            error_log($parts[0] . ' is not a course, apparently');
            $errors[] = array('Line' => 0, 'Code' => $parts[0], 'Title' => $parts[0] . ' - ' . get_lang('CodeDoesNotExists'));
        }
        $i++;
        //found at least one entry that is not a dir or a .
    }
    if ($i == 0) {
        $errors[] = array('Line' => 0, 'Code' => '.', 'Title' => get_lang('NoPDFFoundAtRoot'));
    }
    return $errors;
}
예제 #2
0
	/**
	 * Edit course description
	 *
	 * @param string API secret key
	 * @param string Course id field name
	 * @param string Course id value
	 * @param int Category id from course description
	 * @param string Description title
	 * @param string Course description content
	 */
	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
		$verifKey = $this->verifyKey($secret_key);
		if($verifKey instanceof WSError) {
			$this->handleError($verifKey);
		} else {
			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
			if($course_id instanceof WSError) {
				return $course_id;
			} else {
				// Create the new course description
				$cd = new CourseDescription();
				$cd->set_description_type($course_desc_id);
				$cd->set_title($course_desc_title);
				$cd->set_content($course_desc_content);
				$cd->set_session_id(0);
				// Get course info
				$course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
				// Check if this course description exists
				$descriptions = CourseDescription::get_descriptions($course_id);
				$exists = false;
				foreach($descriptions as $description) {
					if($description->get_description_type() == $course_desc_id) {
						$exists = true;
					}
				}
				if (!$exists) {
					$cd->set_progress(0);
					$cd->insert($course_info['db_name']);
				} else {
					$cd->update($course_info['db_name']);
				}
			}
		}
	}
 /**
  * It's used for adding a course description,
  * render to listing or add view
  */
 public function add()
 {
     $course_description = new CourseDescription();
     $session_id = api_get_session_id();
     $course_description->set_session_id($session_id);
     $data = array();
     if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
         if (!empty($_POST['title']) && !empty($_POST['contentDescription'])) {
             $check = Security::check_token();
             if ($check) {
                 $title = $_POST['title'];
                 $content = $_POST['contentDescription'];
                 $description_type = $_POST['description_type'];
                 if ($description_type >= ADD_BLOCK) {
                     $course_description->set_description_type($description_type);
                     $course_description->set_title($title);
                     $course_description->set_content($content);
                     $course_description->insert(api_get_course_int_id());
                 }
                 Security::clear_token();
                 Display::addFlash(Display::return_message(get_lang('CourseDescriptionUpdated')));
             }
             $this->listing(false);
         } else {
             $data['error'] = 1;
             $data['default_description_titles'] = $course_description->get_default_description_title();
             $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
             $data['default_description_icon'] = $course_description->get_default_description_icon();
             $data['question'] = $course_description->get_default_question();
             $data['information'] = $course_description->get_default_information();
             $data['description_title'] = $_POST['title'];
             $data['description_content'] = $_POST['contentDescription'];
             $data['description_type'] = $_POST['description_type'];
             $this->view->set_data($data);
             $this->view->set_layout('layout');
             $this->view->set_template('add');
             $this->view->render();
         }
     } else {
         $data['default_description_titles'] = $course_description->get_default_description_title();
         $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
         $data['default_description_icon'] = $course_description->get_default_description_icon();
         $data['question'] = $course_description->get_default_question();
         $data['information'] = $course_description->get_default_information();
         $data['description_type'] = $course_description->get_max_description_type();
         // render to the view
         $this->view->set_data($data);
         $this->view->set_layout('layout');
         $this->view->set_template('add');
         $this->view->render();
     }
 }
 /**
  * It's used for adding a course description,
  * render to listing or add view
  */
 public function add()
 {
     $course_description = new CourseDescription();
     $session_id = api_get_session_id();
     $course_description->set_session_id($session_id);
     $data = array();
     if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
         if (!empty($_POST['title']) && !empty($_POST['contentDescription'])) {
             $check = Security::check_token();
             if ($check) {
                 $title = $_POST['title'];
                 if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
                     $content = WCAG_Rendering::prepareXHTML();
                 } else {
                     $content = $_POST['contentDescription'];
                 }
                 $description_type = $_POST['description_type'];
                 if ($description_type >= ADD_BLOCK) {
                     $course_description->set_description_type($description_type);
                     $course_description->set_title($title);
                     $course_description->set_content($content);
                     $affected_rows = $course_description->insert(api_get_course_int_id());
                 }
                 Security::clear_token();
             }
             if ($affected_rows) {
                 $message['add'] = true;
             }
             $this->listing(false, $message);
         } else {
             $data['error'] = 1;
             $data['default_description_titles'] = $course_description->get_default_description_title();
             $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
             $data['default_description_icon'] = $course_description->get_default_description_icon();
             $data['question'] = $course_description->get_default_question();
             $data['information'] = $course_description->get_default_information();
             $data['description_title'] = $_POST['title'];
             $data['description_content'] = $_POST['contentDescription'];
             $data['description_type'] = $_POST['description_type'];
             $this->view->set_data($data);
             $this->view->set_layout('layout');
             $this->view->set_template('add');
             $this->view->render();
         }
     } else {
         $data['default_description_titles'] = $course_description->get_default_description_title();
         $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
         $data['default_description_icon'] = $course_description->get_default_description_icon();
         $data['question'] = $course_description->get_default_question();
         $data['information'] = $course_description->get_default_information();
         $data['description_type'] = $course_description->get_max_description_type();
         // render to the view
         $this->view->set_data($data);
         $this->view->set_layout('layout');
         $this->view->set_template('add');
         $this->view->render();
     }
 }