⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 document.lib.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
								AND last.to_group_id = ".$to_group_id." 								AND last.visibility <> 2";			$result = api_sql_query($sql, __FILE__, __LINE__);			if ($result && Database::num_rows($result) != 0)			{				while ($row = Database::fetch_array($result,'ASSOC'))				{					$document_folders[] = $row['path'];				}				sort($document_folders, SORT_ASC);				//return results				return $document_folders;			}			else			{				return false;			}		}		//no invisible folders		else		{			//get visible folders			$visible_sql = "SELECT path						FROM  ".$TABLE_ITEMPROPERTY."  AS last, ".$TABLE_DOCUMENT."  AS docs						WHERE docs.id = last.ref						AND docs.filetype = 'folder' 						AND last.tool = '".TOOL_DOCUMENT."' 						AND last.to_group_id = ".$to_group_id." 						AND last.visibility = 1";			$visibleresult = api_sql_query($visible_sql, __FILE__, __LINE__);			while ($all_visible_folders = Database::fetch_array($visibleresult,'ASSOC'))			{				$visiblefolders[] = $all_visible_folders['path'];				//echo "visible folders: ".$all_visible_folders['path']."<br>";			}			//get invisible folders			$invisible_sql = "SELECT path 						FROM  ".$TABLE_ITEMPROPERTY."  AS last, ".$TABLE_DOCUMENT."  AS docs						WHERE docs.id = last.ref						AND docs.filetype = 'folder' 						AND last.tool = '".TOOL_DOCUMENT."' 						AND last.to_group_id = ".$to_group_id." 						AND last.visibility = 0";			$invisibleresult = api_sql_query($invisible_sql, __FILE__, __LINE__);			while ($invisible_folders = Database::fetch_array($invisibleresult,'ASSOC'))			{				//get visible folders in the invisible ones -> they are invisible too				//echo "invisible folders: ".$invisible_folders['path']."<br>";				$folder_in_invisible_sql = "SELECT path 								FROM  ".$TABLE_ITEMPROPERTY."  AS last, ".$TABLE_DOCUMENT."  AS docs								WHERE docs.id = last.ref								AND docs.path LIKE '".Database::escape_string($invisible_folders['path'])."/%' 								AND docs.filetype = 'folder' 								AND last.tool = '".TOOL_DOCUMENT."' 								AND last.to_group_id = ".$to_group_id." 								AND last.visibility = 1";				$folder_in_invisible_result = api_sql_query($folder_in_invisible_sql, __FILE__, __LINE__);				while ($folders_in_invisible_folder = Database::fetch_array($folder_in_invisible_result,'ASSOC'))				{					$invisiblefolders[] = $folders_in_invisible_folder['path'];					//echo "<br>folders in invisible folders: ".$folders_in_invisible_folder['path']."<br><br><br>";				}			}			//if both results are arrays -> //calculate the difference between the 2 arrays -> only visible folders are left :)			if (is_array($visiblefolders) && is_array($invisiblefolders))			{				$document_folders = array_diff($visiblefolders, $invisiblefolders);				sort($document_folders, SORT_ASC);				return $document_folders;			}			//only visible folders found			elseif (is_array($visiblefolders))			{				sort($visiblefolders, SORT_ASC);				return $visiblefolders;			}			//no visible folders found			else			{				return false;			}		}	}	/**	 * This deletes a document by changing visibility to 2, renaming it to filename_DELETED_#id	 * Files/folders that are inside a deleted folder get visibility 2	 *	 * @param array $_course	 * @param string $path, path stored in the database	 * @param string ,$base_work_dir, path to the documents folder	 * @return boolean true/false	 * @todo now only files/folders in a folder get visibility 2, we should rename them too.	 */	function delete_document($_course, $path, $base_work_dir)	{		$TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $_course['dbName']);		$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $_course['dbName']);		//first, delete the actual document...		$document_id = DocumentManager :: get_document_id($_course, $path);		$new_path = $path.'_DELETED_'.$document_id;		if ($document_id)		{			if (get_setting('permanently_remove_deleted_files') == 'true') //deleted files are *really* deleted			{				$what_to_delete_sql = "SELECT id FROM ".$TABLE_DOCUMENT." WHERE path='".$path."' OR path LIKE BINARY '".$path."/%'";				//get all id's of documents that are deleted				$what_to_delete_result = api_sql_query($what_to_delete_sql, __FILE__, __LINE__);				if ($what_to_delete_result && Database::num_rows($what_to_delete_result) != 0)				{					//needed to deleted medadata					require_once (api_get_path(SYS_CODE_PATH).'metadata/md_funcs.php');					require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');					$mdStore = new mdstore(TRUE);					//delete all item_property entries					while ($row = Database::fetch_array($what_to_delete_result))					{						//query to delete from item_property table						$remove_from_item_property_sql = "DELETE FROM ".$TABLE_ITEMPROPERTY." WHERE ref = ".$row['id']." AND tool='".TOOL_DOCUMENT."'";						//query to delete from document table						$remove_from_document_sql = "DELETE FROM ".$TABLE_DOCUMENT." WHERE id = ".$row['id']."";						//echo($remove_from_item_property_sql.'<br>');						api_sql_query($remove_from_item_property_sql, __FILE__, __LINE__);						//echo($remove_from_document_sql.'<br>');						api_sql_query($remove_from_document_sql, __FILE__, __LINE__);						//delete metadata						$eid = 'Document'.'.'.$row['id'];						$mdStore->mds_delete($eid);						$mdStore->mds_delete_offspring($eid);					}					//delete documents, do it like this so metadata get's deleted too					//update_db_info('delete', $path);					//throw it away					my_delete($base_work_dir.$path);					return true;				}				else				{					return false;				}			}			else //set visibility to 2 and rename file/folder to qsdqsd_DELETED_#id			{				if (api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'delete', api_get_user_id()))				{					//echo('item_property_update OK');					if (is_file($base_work_dir.$path))                    {                        if(rename($base_work_dir.$path, $base_work_dir.$new_path))    					{    						$sql = "UPDATE $TABLE_DOCUMENT set path='".$new_path."' WHERE id='".$document_id."'";    						if (api_sql_query($sql, __FILE__, __LINE__))    						{    							//if it is a folder it can contain files    							$sql = "SELECT id,path FROM ".$TABLE_DOCUMENT." WHERE path LIKE BINARY '".$path."/%'";    							$result = api_sql_query($sql, __FILE__, __LINE__);    							if ($result && Database::num_rows($result) > 0)    							{    								while ($deleted_items = Database::fetch_array($result,'ASSOC'))    								{    									//echo('to delete also: id '.$deleted_items['id']);    									api_item_property_update($_course, TOOL_DOCUMENT, $deleted_items['id'], 'delete', api_get_user_id());    									//Change path of subfolders and documents in database    									$old_item_path = $deleted_items['path'];    									$new_item_path = $new_path.substr($old_item_path, strlen($path));    									$sql = "UPDATE $TABLE_DOCUMENT set path = '".$new_item_path."' WHERE id = ".$deleted_items['id'];    									api_sql_query($sql, __FILE__, __LINE__);    								}    							}    							return true;    						}    					}                        else                        {                        	//Couldn't rename - file permissions problem?                            error_log(__FILE__.' '.__LINE__.': Error renaming '.$base_work_dir.$path.' to '.$base_work_dir.$new_path.'. This is probably due to file permissions',0);                        }                    }                    else                    {                    	//The file or directory isn't there anymore (on the filesystem)                        // This means it has been removed externally. To prevent a                        // blocking error from happening, we drop the related items from the                        // item_property and the document table.                        error_log(__FILE__.' '.__LINE__.': System inconsistency detected. The file or directory '.$base_work_dir.$path.' seems to have been removed from the filesystem independently from the web platform. To restore consistency, the elements using the same path will be removed from the database',0);                        $sql = "SELECT id FROM $TABLE_DOCUMENT WHERE path='".$path."' OR path LIKE BINARY '".$path."/%'";                        $res = Database::query($sql,__FILE__,__LINE__);                        while ( $row = Database::fetch_array($res) ) {                        	$sqlipd = "DELETE FROM $TABLE_ITEMPROPERTY WHERE ref = ".$row['id']." AND tool='".TOOL_DOCUMENT."'";                            $resipd = Database::query($sqlipd,__FILE__,__LINE__);                            $sqldd = "DELETE FROM $TABLE_DOCUMENT WHERE id = ".$row['id'];                            $resdd = Database::query($sqldd,__FILE__,__LINE__);                         }                    }				}			}		}        return false;	}	/**	 * Gets the id of a document with a given path	 *	 * @param array $_course	 * @param string $path	 * @return int id of document / false if no doc found	 */	function get_document_id($_course, $path)	{		$TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $_course['dbName']);		$sql = "SELECT id FROM $TABLE_DOCUMENT WHERE path LIKE BINARY '$path'";		$result = api_sql_query($sql, __FILE__, __LINE__);		if ($result && Database::num_rows($result) == 1)		{			$row = Database::fetch_array($result);			return $row[0];		}		else		{			return false;		}	}			/**	 * Allow to set a specific document as a new template for FCKEditor for a particular user in a particular course	 *	 * @param string $title	 * @param string $description	 * @param int $document_id_for_template the document id	 * @param string $couse_code	 * @param int $user_id	 */	function set_document_as_template($title, $description, $document_id_for_template, $couse_code, $user_id){				$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);				$title = Database::escape_string($title);		$description = Database::escape_string($description);		$document_id_for_template = Database::escape_string($document_id_for_template);		$couse_code = Database::escape_string($couse_code);		$user_id = Database::escape_string($user_id);				$sql = 'INSERT INTO '.$table_template.'(title, description, course_code, user_id, ref_doc)				VALUES ("'.$title.'", "'.$description.'", "'.$couse_code.'", "'.$user_id.'", "'.$document_id_for_template.'")';				api_sql_query($sql);			}			/**	 * Unset a document as template	 *	 * @param int $document_id	 * @param string $couse_code	 * @param int $user_id	 */	function unset_document_as_template($document_id, $couse_code, $user_id){				$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);				$sql = 'SELECT id FROM '.$table_template.' WHERE course_code="'.$couse_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"';		$result = api_sql_query($sql);		$template_id = Database::result($result,0,0);				include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');		my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg');				$sql = 'DELETE FROM '.$table_template.' WHERE course_code="'.$couse_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"';				api_sql_query($sql);			}	}//end class DocumentManager?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -