. */ /** * @brief Contains the LinkController Class * * * @file * @author Arnaud Veber * @date $date$ * @version $Revision$ * @ingroup core */ //Loads the require class try { require_once('core/class/class_db.php'); require_once('core/class/class_history.php'); } catch (Exception $e) { echo $e->getMessage() . ' // '; } class LinkController { private $previousId = ' '; private $level = 0; public function formatMap($arrayToFormat, $sens) { $this->level++; $core = new core_tools(); $core->test_user(); $return = ''; foreach ($arrayToFormat as $key => $value) { $infos = $this->getDocInfos($key, $_SESSION['current_basket']['coll_id']); $infos['subject'] = preg_replace("/\r\n|\r|\n/",'
',$infos['subject']); $return .= '
'; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= ''; if ($core->test_service('add_links', 'apps', false) && $this->level <= 1) { if ($sens == 'asc') { $delParent = $key; $delChild = $_SESSION['doc_id']; } else { $delParent = $_SESSION['doc_id']; $delChild = $key; } $return .= ''; $return .= ''; } $return .= ''; $return .= '
'; $return .= ''; $return .= ''; $return .= ''; $return .= ''; if ($_SESSION['current_basket']['coll_id'] == 'letterbox_coll') { $return .= ''; } elseif ($_SESSION['current_basket']['coll_id'] == 'business_coll') { $return .= ''; } $return .= ''.$key.'' ; $return .= ''; $return .= ''; if ($_SESSION['current_basket']['coll_id'] == 'letterbox_coll') { $return .= $_SESSION['coll_categories']['letterbox_coll'][$infos['category_id']]; } elseif ($_SESSION['current_basket']['coll_id'] == 'business_coll') { $return .= $_SESSION['coll_categories']['business_coll'][$infos['category_id']]; } $return .= ''; $date = explode('-', substr($infos['doc_date'], 0, 10)); $return .= $date[2].' '.$date[1].' '.$date[0]; $return .= ''; $return .= ''; $return .= $infos['subject']; $return .= ''; $return .= ''; $return .= $infos['entity_label'].' ('.$infos['destination'].')'; $return .= ''; $status = $this->getStatus($infos['status']); $return .= $status; $return .= ''; $return .= ''; $return .= ''; $return .= ''; $return .= '
'; if (is_array($value)) { $return .= $this->formatMap($value, $sens); } $return .= '
'; } $this->level--; return $return; } public function getMap($parentId, $collection, $sens) { if (!empty($parentId) && !empty($collection)) { if ($sens == 'asc') { $links = $this->getLinksAsc($parentId, $collection); } else { $links = $this->getLinksDesc($parentId, $collection); } $linksArray = explode('||', $links); for ($i=0; $ipreviousId)) { $this->previousId .= $parentId . ' '; //echo $this->previousId . '
'; $return[$linksArray[$i]] = $this->getMap($linksArray[$i], $collection, $sens); } } else { $return = 'last'; } } } return $return; } private function getLinks($parentId, $collection) { $db = new dbquery; $db->connect(); $query = "SELECT res_child FROM res_linked WHERE coll_id='" . $collection . "' AND res_parent=" . $parentId; $result = $db->query($query); if ($result) { $i = 0; $links = ''; while ($row = $db->fetch_assoc($result)) { $links .= $row['res_child'].'||'; $i++; } if ($i > 0) { $return = substr($links, 0, -2); } } else { $return = 'Problème lors de la requête : '.$query; } return $return; } private function getLinksDesc($parentId, $collection) { $db = new dbquery; $db->connect(); $query = "SELECT res_child FROM res_linked WHERE coll_id='" . $collection . "' AND res_parent=" . $parentId; $result = $db->query($query); if ($result) { $i = 0; $links = ''; while ($row = $db->fetch_assoc($result)) { $links .= $row['res_child'].'||'; $i++; } if ($i > 0) { $return = substr($links, 0, -2); } } else { $return = 'Problème lors de la requête : '.$query; } return $return; } private function getLinksAsc($parentId, $collection) { $db = new dbquery; $db->connect(); $query = "SELECT res_parent FROM res_linked WHERE coll_id='" . $collection . "' AND res_child=" . $parentId; $result = $db->query($query); if ($result) { $i = 0; $links = ''; while ($row = $db->fetch_assoc($result)) { $links .= $row['res_parent'].'||'; $i++; } if ($i > 0) { $return = substr($links, 0, -2); } } else { $return = 'Problème lors de la requête : '.$query; } return $return; } private function getDocInfos($id, $collection) { if ($collection == 'letterbox_coll') { $vue = 'res_view_letterbox'; } elseif ($collection == 'business_coll') { $vue = 'res_view_business'; } else { $vue = ''; } if ($vue <> '') { $db = new dbquery; $db->connect(); $query = "SELECT * FROM ".$vue." WHERE res_id = ".$id; $result = $db->query($query); if ($result) { $i = 0; while ($row = $db->fetch_assoc($result)) { $return = $row; $i++; } } } else { $return = false; } return $return; } public function getStatus($status) { $db = new dbquery; $db->connect(); $query = "SELECT label_status FROM status WHERE id = '" . $status . "'"; $result = $db->query($query); if ($result) { $i = 0; while ($row = $db->fetch_assoc($result)) { $return = $row['label_status']; $i++; } } return $return; } public function nbDirectLink($id, $collection, $sens) { $i = 0; $db = new dbquery; $db->connect(); if ($sens == 'desc' || $sens == 'all') { $query = "SELECT res_child FROM res_linked WHERE coll_id='" . $collection . "' AND res_parent=" . $id; $result = $db->query($query); if ($result) { while ($row = $db->fetch_assoc($result)) { $i++; } } } if ($sens == 'asc' || $sens == 'all') { $query = "SELECT res_parent FROM res_linked WHERE coll_id='" . $collection . "' AND res_child=" . $id; $result = $db->query($query); if ($result) { while ($row = $db->fetch_assoc($result)) { $i++; } } } return $i; } }