function loadFile() { $this->_ref_file = new CFile(); if ($this->file_id) { $this->_ref_file->load($this->file_id); } }
function loadTimedPictures($results, $time_min, $time_max) { $type_id = $this->value_type_id; if (!isset($results[$type_id]["none"])) { return $this->_graph_data = array(); } $data = $results[$type_id]["none"]; foreach ($data as $_i => $_d) { $data[$_i]["position"] = $this->getPosition($_d["datetime"], $time_min, $time_max); if ($_d["file_id"]) { $file = new CFile(); $file->load($_d["file_id"]); $data[$_i]["file"] = $file; } } return $this->_graph_data = $data; }
public function delete(CAppUI $AppUI = null) { global $AppUI; $perms = $AppUI->acl(); $result = false; $this->_error = array(); /* * TODO: This should probably use the canDelete method from above too to * not only check permissions but to check dependencies... luckily the * previous version didn't check it either, so we're no worse off. */ if ($perms->checkModuleItem('projects', 'delete', $this->project_id)) { $q = $this->_query; $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project = ' . (int) $this->project_id); $tasks_to_delete = $q->loadColumn(); $q->clear(); foreach ($tasks_to_delete as $task_id) { $q->setDelete('user_tasks'); $q->addWhere('task_id =' . $task_id); $q->exec(); $q->clear(); $q->setDelete('task_dependencies'); $q->addWhere('dependencies_req_task_id =' . (int) $task_id); $q->exec(); $q->clear(); } $q->setDelete('tasks'); $q->addWhere('task_project =' . (int) $this->project_id); $q->exec(); $q->clear(); $q->addTable('files'); $q->addQuery('file_id'); $q->addWhere('file_project = ' . (int) $this->project_id); $files_to_delete = $q->loadColumn(); $q->clear(); foreach ($files_to_delete as $file_id) { $file = new CFile(); $file->load($file_id); $file->delete($AppUI); } $q->setDelete('events'); $q->addWhere('event_project =' . (int) $this->project_id); $q->exec(); $q->clear(); // remove the project-contacts and project-departments map $q->setDelete('project_contacts'); $q->addWhere('project_id =' . (int) $this->project_id); $q->exec(); $q->clear(); $q->setDelete('project_departments'); $q->addWhere('project_id =' . (int) $this->project_id); $q->exec(); $q->clear(); $q->setDelete('tasks'); $q->addWhere('task_represents_project =' . (int) $this->project_id); $q->clear(); if ($msg = parent::delete()) { return $msg; } return true; } return $result; }
*/ // post values $dispo = CValue::post("tab_disposition"); $user_id = CValue::post("user_id"); $cat_id = CValue::post("category_id"); $print = CValue::post("print", 0); // files $file_array = CValue::post("file"); $data = $file_array[$dispo]; // context $object_guid = CValue::post("context_guid"); $context = CMbObject::loadFromGuid($object_guid); // get data uri foreach ($data as $_key => &$_data) { $file = new CFile(); $file->load($_data["file_id"]); $file->getDataURI(); $_data["file_uri"] = $file->_data_uri; } //user $user = CMediusers::get($user_id); // file $file = new CFile(); $file->setObject($context); $file->file_name = CAppUI::tr("CFile-create-mozaic") . " de " . CAppUI::tr($context->_class) . " du " . CMbDT::dateToLocale(CMbDT::date()) . ".pdf"; $file->file_type = "application/pdf"; $file->file_category_id = $cat_id; $file->author_id = CMediusers::get()->_id; $file->fillFields(); $file->updateFormFields(); $file->forceDir();
<?php /* FILES $Id$ */ if (!defined('DP_BASE_DIR')) { die('You should not access this file directly.'); } //addfile sql $file_id = intval(dPgetParam($_POST, 'file_id', 0)); $coReason = dPgetParam($_POST, 'file_co_reason', ''); $obj = new CFile(); if ($file_id) { $obj->_message = 'updated'; $oldObj = new CFile(); $oldObj->load($file_id); } else { $obj->_message = 'added'; } $obj->file_category = intval(dPgetParam($_POST, 'file_category', 0)); if (!$obj->bind($_POST)) { $AppUI->setMsg($obj->getError(), UI_MSG_ERROR); $AppUI->redirect(); } if (!ini_get('safe_mode')) { set_time_limit(600); } ignore_user_abort(1); $obj->checkout($AppUI->user_id, $file_id, $coReason); // We now have to display the required page // Destroy the post stuff, and allow the page to display index.php again. $a = 'index'; unset($_GET['a']);
function store($object_id) { global $AppUI, $db, $_FILES, $m, $_POST; $file_uploaded = false; // instantiate the file object and eventually load exsiting file data $obj = new CFile(); if ($_POST[$this->field_name . '_id']) { $obj->load($_POST[$this->field_name . '_id']); // create an old object for the case that // the file must be replaced if ($_POST[$this->field_name . '_id'] > 0) { $oldObj = new CFile(); $oldObj->load($_POST[$this->field_name . '_id']); } } // if the cf lives in the projects module // affiliate the file to the suitable project if ($m == 'projects' && !empty($_POST['project_id'])) { $obj->file_project = $_POST['project_id']; } // todo: implement task affiliation here, too $upload = null; if (isset($_FILES[$this->field_name])) { $upload = $_FILES[$this->field_name]; if ($upload['size'] > 0) { // store file with a unique name $obj->file_name = $upload['name']; $obj->file_type = $upload['type']; $obj->file_size = $upload['size']; $obj->file_date = str_replace("'", '', $db->DBTimeStamp(time())); $obj->file_real_filename = uniqid(rand()); $obj->file_owner = $AppUI->user_id; $obj->file_version++; $obj->file_version_id = $obj->file_id; $res = $obj->moveTemp($upload); if ($res) { $file_uploaded = true; } if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } else { // reset the cf field_name to the file_id $this->setValue($obj->file_id); } } } // Delete the existing (old) file in case of file replacement // (through addedit not through c/o-versions) if ($_POST[$this->field_name . '_id'] && $upload['size'] > 0 && $file_uploaded) { $oldObj->deleteFile(); } if ($upload['size'] > 0 && $file_uploaded) { return parent::store($object_id); } else { if ($upload['size'] > 1 && !$file_uploaded) { $AppUI->setMsg('File could not be stored!', UI_MSG_ERROR, true); return true; } } }
die('You should not access this file directly.'); } $file_id = intval(w2PgetParam($_GET, 'file_id', 0)); // check permissions for this record $perms =& $AppUI->acl(); $canEdit = $perms->checkModuleItem($m, 'edit', $file_id); if (!$canEdit) { $AppUI->redirect('m=public&a=access_denied'); } $canAdmin = $perms->checkModule('system', 'edit'); $file_parent = intval(w2PgetParam($_GET, 'file_parent', 0)); // check if this record has dependencies to prevent deletion $msg = ''; $obj = new CFile(); // load the record data if ($file_id > 0 && !$obj->load($file_id)) { $AppUI->setMsg('File'); $AppUI->setMsg('invalidID', UI_MSG_ERROR, true); $AppUI->redirect(); } // setup the title block $titleBlock = new CTitleBlock('Checkout', 'folder5.png', $m, "{$m}.{$a}"); $titleBlock->addCrumb('?m=files', 'files list'); $titleBlock->show(); if ($obj->file_project) { $file_project = $obj->file_project; } if ($obj->file_task) { $file_task = $obj->file_task; $task_name = $obj->getTaskName(); } elseif ($file_task) {
public function testLoad() { $this->obj->bind($this->post_data); $result = $this->obj->store(); $this->assertTrue($result); $item = new CFile(); $item->overrideDatabase($this->mockDB); $this->post_data['file_id'] = $this->obj->file_id; $this->mockDB->stageHash($this->post_data); $item->load($this->obj->file_id); $this->assertEquals($this->obj->file_name, $item->file_name); $this->assertEquals($this->obj->file_real_filename, $item->file_real_filename); $this->assertEquals($this->obj->file_parent, $item->file_parent); $this->assertEquals($this->obj->file_description, $item->file_description); $this->assertNotEquals($this->obj->file_date, ''); }
<?php /** * This file exists exclusively because it allows the Files module to use the * same url generation that the other modules do. Aka.. it makes our lives * easier and it's one less thing to have to code around. */ if (!defined('W2P_BASE_DIR')) { die('You should not access this file directly.'); } $file_id = (int) w2PgetParam($_GET, 'file_id', 0); $file = new CFile(); if (!$file->load($file_id)) { $AppUI->redirect(ACCESS_DENIED); } header("Location: fileviewer.php?file_id=" . $file_id);
<?php /* FILES $Id$ */ if (!defined('DP_BASE_DIR')) { die('You should not access this file directly.'); } //addfile sql $file_id = intval(dPgetParam($_POST, 'file_id', 0)); $coReason = dPgetParam($_POST, 'file_co_reason', ''); $co_cancel = intval(dPgetParam($_POST, 'co_cancel', 0)); $not = dPgetParam($_POST, 'notify', '0'); $notcont = dPgetParam($_POST, 'notify_contacts', '0'); $obj = new CFile(); $obj->load($file_id); //set checkout messages if ($msg = $obj->checkout($AppUI->user_id, $coReason)) { $AppUI->setMsg($msg, UI_MSG_ERROR); } else { $AppUI->setMsg('File checkout completed', UI_MSG_OK); //Notification $obj->_message = $co_cancel ? 'reverted' : 'checked out'; if ($not) { $obj->notify(); } if ($notcont) { $obj->notifyContacts(); } } //Checkout Cancellation if ($co_cancel) { if ($msg = $obj->checkout('', '')) {
<?php /** * $Id: $ * * @package Mediboard * @subpackage Cabinet * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision: $ */ CCanDo::checkRead(); $file_id = CValue::get("id"); $name_readonly = CValue::get("name_readonly", 0); $file = new CFile(); $file->load($file_id); $file->canDo(); $object_id = CValue::get("object_id"); $object_class = CValue::get("object_class"); $smarty = new CSmartyDP(); $smarty->assign("_file", $file); $smarty->assign("object_id", $object_id); $smarty->assign("object_class", $object_class); $smarty->assign("name_readonly", $name_readonly); $smarty->display("inc_widget_line_file.tpl");
require_once $AppUI->getModuleClass('companies'); require_once $AppUI->getModuleClass('projects'); require_once $AppUI->getModuleClass('tasks'); $file_task = intval(dPgetParam($_GET, 'file_task', 0)); $file_parent = intval(dPgetParam($_GET, 'file_parent', 0)); $file_project = intval(dPgetParam($_GET, 'project_id', 0)); $file_helpdesk_item = intval(dPgetParam($_GET, 'file_helpdesk_item', 0)); $q = new DBQuery(); // check if this record has dependencies to prevent deletion $msg = ''; $obj = new CFile(); $canDelete = $obj->canDelete($msg, $file_id); // load the record data // $obj = null; if ($file_id > 0) { if (!$obj->load($file_id)) { $AppUI->setMsg('File'); $AppUI->setMsg('invalidID', UI_MSG_ERROR, true); $AppUI->redirect(); } // Check to see if the task or the project is allowed. if ($obj->file_task && !getPermission('tasks', 'view', $obj->file_task) || $obj->file_project && !getPermission('projects', 'view', $obj->file_project)) { $AppUI->redirect('m=public&a=access_denied'); } } // If the file is checked out, check a few things, like if the user // is trying to check it in, or if they are trying to overwrite. if ($obj->file_checkout) { if (!$ci || $obj->file_checkout != $AppUI->user_id) { $AppUI->setMsg('File is currently checked out - it must be checked in first'); $AppUI->redirect('m=public&a=access_denied');
<?php /* fileS $Id$ */ if (!defined('DP_BASE_DIR')) { die('You should not access this file directly.'); } global $AppUI; $selected = dPgetParam($_POST, 'bulk_selected_file', 0); $redirect = dPgetParam($_POST, 'redirect', ''); $bulk_file_project = dPgetParam($_POST, 'bulk_file_project', 'O'); $bulk_file_folder = dPgetParam($_POST, 'bulk_file_folder', 'O'); if (is_array($selected) && count($selected)) { $upd_file = new CFile(); foreach ($selected as $key => $val) { if ($key) { $upd_file->load($key); } if (isset($_POST['bulk_file_project']) && $bulk_file_project != '' && $bulk_file_project != 'O') { if ($upd_file->file_id) { // move the file on filesystem if the affiliated project was changed if ($upd_file->file_project != $bulk_file_project) { $oldProject = $upd_file->file_project; $upd_file->file_project = $bulk_file_project; $res = $upd_file->moveFile($oldProject, $upd_file->file_real_filename); if (!$res) { $AppUI->setMsg('At least one File could not be moved', UI_MSG_ERROR); } } $upd_file->store(); } }
/** * $Id$ * * @category Drawing * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ CCanDo::checkEdit(); $draw_id = CValue::get('id'); $context_guid = CValue::get("context_guid"); $draw = new CFile(); $draw->load($draw_id); $draw->loadRefsNotes(); $draw->loadRefAuthor(); $draw->loadRefsNotes(); $draw->getBinaryContent(); $user = CMediusers::get(); $user->loadRefFunction(); $functions = $user->loadRefsSecondaryFunctions(); $admin = $user->isAdmin(); $files_in_context = array(); $object = null; if ($context_guid) { $object = CMbObject::loadFromGuid($context_guid); if ($object->_id) { $object->loadRefsFiles(); foreach ($object->_ref_files as $file_id => $_file) {
/** * Ajoute les données des graphiques de supervision * * @param CTemplateManager $template The template manager * @param CMbObject $object The host object * @param string $name The field name * * @return void */ static function addObservationDataToTemplate(CTemplateManager $template, CMbObject $object, $name) { $prefix = "Supervision"; $group_id = CGroups::loadCurrent()->_id; $results = array(); $times = array(); if ($object->_id) { list($results, $times) = CObservationResultSet::getResultsFor($object, false); $times = array_combine($times, $times); } // CSupervisionGraphAxis $axis = new CSupervisionGraphAxis(); $ds = $axis->getDS(); $where = array("supervision_graph_axis.in_doc_template" => "= '1'", "supervision_graph.owner_class" => "= 'CGroups'", "supervision_graph.owner_id" => $ds->prepare("= ?", $group_id)); $ljoin = array("supervision_graph" => "supervision_graph.supervision_graph_id = supervision_graph_axis.supervision_graph_id"); $order = array("supervision_graph.title", "supervision_graph_axis.title"); /** @var CSupervisionGraphAxis[] $axes */ $axes = $axis->loadList($where, $order, null, null, $ljoin); CStoredObject::massLoadFwdRef($axes, "supervision_graph_id", null, true); foreach ($axes as $_axis) { $_graph = $_axis->loadRefGraph(); $_series = $_axis->loadRefsSeries(); $_axis->loadRefsLabels(); $_data = array_fill_keys($times, array()); foreach ($_series as $_serie) { $_unit_id = $_serie->value_unit_id ?: "none"; $_unit_label = $_serie->loadRefValueUnit(); if (!isset($results[$_serie->value_type_id][$_unit_id])) { continue; } foreach ($results[$_serie->value_type_id][$_unit_id] as $_value) { foreach ($times as $_time) { if ($_value["datetime"] != $_time) { continue; } $_value["unit"] = $_unit_label->label; $_data["{$_time}"][$_serie->_id] = $_value; break; } } } $view = ""; if (count($_data)) { $smarty = new CSmartyDP("modules/dPsalleOp"); $smarty->assign("data", $_data); $smarty->assign("series", $_series); $smarty->assign("times", $times); $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0); $view = preg_replace('`([\\n\\r])`', '', $view); } $template->addProperty("{$name} - {$prefix} - {$_graph->title} - {$_axis->title}", trim($view), "", false); } // CSupervisionTimedPicture // CSupervisionTimedData $data = array("CSupervisionTimedPicture", "CSupervisionTimedData"); foreach ($data as $_class) { /** @var CSupervisionTimedPicture|CSupervisionTimedData $_object */ $_object = new $_class(); $_table = $_object->_spec->table; $_ds = $_object->getDS(); $where = array("{$_table}.in_doc_template" => "= '1'", "{$_table}.owner_class" => "= 'CGroups'", "{$_table}.owner_id" => $_ds->prepare("= ?", $group_id)); $order = "title"; /** @var CSupervisionTimedPicture[]|CSupervisionTimedData[] $_objects */ $_objects = $_object->loadList($where, $order); foreach ($_objects as $_timed) { $_data = array_fill_keys($times, null); if (!isset($results[$_timed->value_type_id])) { continue; } foreach ($results[$_timed->value_type_id]["none"] as $_value) { foreach ($times as $_time) { if ($_value["datetime"] != $_time) { continue; } if ($_value["file_id"]) { $_file = new CFile(); $_file->load($_value["file_id"]); $_value["datauri"] = $_file->getDataURI(); $_value["file"] = $_file; } $_data["{$_time}"] = $_value; break; } } $view = ""; if (count($_data)) { $smarty = new CSmartyDP("modules/dPsalleOp"); $smarty->assign("data", $_data); $smarty->assign("times", $times); $smarty->assign("timed_data", true); $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0); $view = preg_replace('`([\\n\\r])`', '', $view); } $template->addProperty("{$name} - {$prefix} - {$_timed->title}", trim($view), "", false); } } }
/** * Applique les champs variables sur une source html * * @param string $_source source html * * @return void */ function renderDocument($_source) { $fields = array(); $values = array(); $fields_regex = array(); $values_regex = array(); foreach ($this->sections as $properties) { foreach ($properties as $key => $property) { if (strpos($key, ' - ') === false) { foreach ($property as $_property) { if ($_property["valueHTML"] && isset($_property["options"]["barcode"])) { $options = $_property["options"]["barcode"]; $image = $this->getBarcodeDataUri($_property["valueHTML"], $options); $fields[] = utf8_decode(html_entity_decode("src=\"{$_property['fieldHTML']}\"")); $values[] = "src=\"{$image}\""; } elseif (isset($_property["options"]["data"])) { $data = $_property["options"]["data"]; $fields_regex[] = $this->getDataRegex($data); $values_regex[] = $_property["valueHTML"]; } else { $fields[] = $_property["fieldHTML"]; $values[] = nl2br($_property["valueHTML"]); } } } else { if ($property["valueHTML"] && isset($property["options"]["barcode"])) { $options = $property["options"]["barcode"]; $image = $this->getBarcodeDataUri($property["valueHTML"], $options); $fields[] = "src=\"{$property['fieldHTML']}\""; $values[] = "src=\"{$image}\""; } else { if (isset($property["options"]["data"])) { $data = $property["options"]["data"]; $fields_regex[] = $this->getDataRegex($data); $values_regex[] = $property["valueHTML"]; } else { if ($property["valueHTML"] && isset($property["options"]["image"])) { $file = new CFile(); $file->load($property['value']); $src = $file->getDataURI(); $fields[] = "src=\"{$property['fieldHTML']}\""; $values[] = "src=\"{$src}\""; } else { $property["fieldHTML"] = preg_replace("/'/", ''', $property["fieldHTML"]); $fields[] = $property["fieldHTML"]; $values[] = nl2br($property["valueHTML"]); } } } } } } if (count($fields_regex)) { $_source = preg_replace($fields_regex, $values_regex, $_source); } if (count($fields)) { $_source = str_ireplace($fields, $values, $_source); } if (count($fields_regex) || count($fields)) { $this->document = $_source; } }
/** * load files linked to the present attachment * * @return CFile */ function loadFiles() { //a file is already linked and we have the id $file = new CFile(); if ($this->file_id) { $file->load($this->file_id); $file->loadRefsFwd(); //TODO : fix this } else { $file->setObject($this); $file->loadMatchingObject(); } $file->updateFormFields(); return $this->_file = $file; }
$AppUI =& $_SESSION['AppUI']; require_once DP_BASE_DIR . '/includes/permissions.php'; $perms =& $AppUI->acl(); $canRead = $perms->checkModule('files', 'view'); if (!$canRead) { $AppUI->redirect('m=public&a=access_denied'); } $file_id = isset($_GET['file_id']) ? (int) $_GET['file_id'] : 0; if ($file_id) { // projects tat are denied access require_once $AppUI->getModuleClass('projects'); require_once $AppUI->getModuleClass('files'); $project = new CProject(); $allowedProjects = $project->getAllowedRecords($AppUI->user_id, 'project_id, project_name'); $fileclass = new CFile(); $fileclass->load($file_id); $allowedFiles = $fileclass->getAllowedRecords($AppUI->user_id, 'file_id, file_name'); if (count($allowedFiles) && !array_key_exists($file_id, $allowedFiles)) { $AppUI->redirect('m=public&a=access_denied'); } $q = new DBQuery(); $q->addTable('files'); if ($fileclass->file_project) { $project->setAllowedSQL($AppUI->user_id, $q, 'file_project'); } $q->addWhere('file_id = ' . $file_id); $sql = $q->prepare(); if (!db_loadHash($sql, $file)) { $AppUI->redirect('m=public&a=access_denied'); } /*
if (empty($task_end_date) || !empty($end_date) && $task_end_date->dateDiff($end_date)) { $obj->addReminder(); } // If there was a file that was attached to both the task, and the task // has moved projects, we need to move the file as well if ($move_files) { require_once $AppUI->getModuleClass('files'); $filehandler = new CFile(); $q = new DBQuery(); $q->addTable('files', 'f'); $q->addQuery('file_id'); $q->addWhere('file_task = ' . (int) $obj->task_id); $files = $q->loadColumn(); if (!empty($files)) { foreach ($files as $file) { $filehandler->load($file); $realname = $filehandler->file_real_filename; $filehandler->file_project = $obj->task_project; $filehandler->moveFile($move_files, $realname); $filehandler->store(); } } } $AppUI->setMsg($task_id ? 'Task updated' : 'Task added', UI_MSG_OK); } if (isset($hassign)) { $obj->updateAssigned($hassign, $hperc_assign_ar); } if (isset($hdependencies)) { // && !empty($hdependencies)) { // there are dependencies set!