Skip to content
Snippets Groups Projects
LinkController.php 12 KiB
Newer Older
  • Learn to ignore specific revisions
  • Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    <?php
    /**
    
    * Copyright Maarch since 2008 under licence GPLv3.
    * See LICENCE.txt file at the root folder for more details.
    * This file is part of Maarch software.
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    *
    
    * @brief  LinkController
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    *
    
    * @author  dev <dev@maarch.org>
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    * @ingroup core
    */
    
    //Loads the require class
    
    require_once 'core/class/class_history.php';
    include 'apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'definition_mail_categories.php';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    class LinkController
    {
        private $previousId = ' ';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        private $level = 0;
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        public function formatMap($arrayToFormat, $sens)
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        {
    
            $db = new Database();
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $core = new core_tools();
            $core->test_user();
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $return = '';
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            foreach ($arrayToFormat as $key => $value) {
    
                //GET RES INFOS
    
                $stmt = $db->query('SELECT dest_user, status FROM res_letterbox WHERE res_id = ?', array($key));
                $otherInfos = $stmt->fetchObject();
                $chronoNumber = $this->getAltIdentifier($key);
    
                if (!empty($infos['exp_contact_id']['show_value'])) {
                    $contact = $infos['exp_contact_id']['show_value'];
                } elseif (!empty($infos['dest_contact_id']['show_value'])) {
                    $contact = $infos['dest_contact_id']['show_value'];
                } elseif (!empty($infos['exp_user_id']['show_value'])) {
                    $contact = $infos['exp_user_id']['show_value'];
                } elseif (!empty($infos['dest_user_id']['show_value'])) {
                    $contact = $infos['dest_user_id']['show_value'];
    
                } elseif ($infos['category_id']['value'] != 'attachment') {
    
                    $contact = _MULTI_CONTACT;
                }
    
                $infos['subject'] = preg_replace("/\r\n|\r|\n/", '<br/>', $infos['subject']);
    
                if (!empty($infos['subject']['show_value'])) {
                    $subjectShowValue = $infos['subject']['show_value'];
                }
    
                $return .= '<div id="ged_'.$key.$sens.'" class="linkDiv">';
    
                $return .= '<table style="width:100%;text-align:left;font-size:15px;cursor:pointer;" title="'._ACCESS_TO_DETAILS.'">';
                $return .= '<tr>';
                $status = $this->getStatus($otherInfos->status);
                $img_class = substr($status['img_filename'], 0, 2);
                $return .= '<td style="width:14%;text-align:center;" title="'.$status['label_status'].'" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
                $return .= '<i class="'.$img_class.' '.$status['img_filename'].' '.$img_class.'-2x" ></i> ';
                $return .= '</td>';
                $return .= '<td colspan="2" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
    
                $return .= '<b>'.$subjectShowValue.'</b>';
    
                $return .= '</td>';
                $return .= '<td colspan="2" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
                $return .= '</td>';
                $return .= '<td colspan="3" style="font-size:12px;" align="right" title="'._CONTACT.'" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
                $return .= '<i class="fa fa-user fa-2x" style="font-size:10px;"></i> ';
                $return .= $contact;
                $return .= '</td>';
                $return .= '</tr>';
                $return .= '<tr>';
                $return .= '<td style="width:14%;text-align:center;" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
                $return .= (_ID_TO_DISPLAY == 'res_id' ? $key : $chronoNumber);
                $return .= '</td>';
                $return .= '<td style="font-size:12px;width:16%;" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
                $return .= $infos['category_id']['show_value'];
                $return .= '</td>';
                $return .= '<td style="font-size:12px;width:14%" title="'._DOC_DATE.'" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
    
                $return .= '<i class="fa fa-calendar-alt fa-2x" style="font-size:10px;"></i> ';
    
                $date = explode('-', substr($infos['doc_date']['show_value'], 0, 10));
                $return .= $date[2].' '.$date[1].' '.$date[0];
                $return .= '</td>';
                $return .= '<td style="font-size:12px;width:14%" title="'._DEST_USER.'" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
                $return .= '<i class="fa fa-share-alt fa-2x" style="font-size:10px;"></i> ';
                $return .= $otherInfos->dest_user;
                $return .= '</td>';
                $return .= '<td style="font-size:12px;width:24%" title="'._DEPARTMENT_DEST.'" onclick="window.top.location.href=\'index.php?page=details&dir=indexing_searching&id='.$key.'\'">';
                $return .= '<i class="fa fa-sitemap fa-2x" style="font-size:10px;"></i> ';
                $return .= $infos['destination']['show_value'];
                $return .= '</td>';
                if ($core->is_module_loaded('visa')) {
                    require_once 'modules'.DIRECTORY_SEPARATOR.'visa'.DIRECTORY_SEPARATOR
                                .'class'.DIRECTORY_SEPARATOR
                                .'class_modules_tools.php';
                    $return .= '<td style="font-size:12px;width:16%" title="'._VISA_USERS.'">';
    
                    $visa = new visa();
    
                    $users_visa_list = $visa->getUsersCurrentVis($key);
                    if (!empty($users_visa_list)) {
                        $users_visa_list = implode(', ', $users_visa_list);
                        $return .= '<i class="fa fa-list-ol fa-2x" style="font-size:10px;"></i> ';
                        $return .= $users_visa_list;
                    }
                    $return .= '</td>';
                }
    
                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;
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                    }
    
                    $return .= '<td align="right">';
    
                    $return .= '<div align="center" class="iconDoc"><a href="index.php?display=true&dir=indexing_searching&page=view_resource_controler&id='.$key.'" target="_blank" title="'._VIEW_DOC.'"><i class="fa fa-download fa-2x" title="'._VIEW_DOC.'"></i><span><img src="../../rest/resources/'.$key.'/thumbnail"></span></a></div>';
    
                    $return .= '</td>';
                    $return .= '<td align="right">';
                    $return .= '<span onclick="';
                    $return .= 'if(confirm(\'Voulez-vous supprimer la liaison ?\')){';
                    $return .= 'addLinks(';
                    $return .= '\''.$_SESSION['config']['businessappurl'].'index.php?page=add_links&display=true\', ';
                    $return .= '\''.$delChild.'\' ,';
                    $return .= '\''.$delParent.'\' ,';
                    $return .= '\'del\',';
    
    
    Florian Azizian's avatar
    Florian Azizian committed
                    $return .= '\'res_view_letterbox\'';
    
    
                    $return .= ');}';
                    $return .= '">';
                    $return .= '<i class="fa fa-unlink fa-2x" title="'._DEL_LINK.'" style="cursor:pointer;"></i>';
                    $return .= '</span>';
                    $return .= '</td>';
                }
                $return .= '</tr>';
                $return .= '</table>';
                if (is_array($value)) {
                    $return .= $this->formatMap($value, $sens);
                }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                $return .= '</div>';
            }
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            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; $i < count($linksArray); ++$i) {
                    if ($linksArray[$i] != '') {
                        if (!preg_match('/'.' '.$linksArray[$i].' '.'/', $this->previousId)) {
                            $this->previousId .= $parentId.' ';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                            $return[$linksArray[$i]] = $this->getMap($linksArray[$i], $collection, $sens);
                        }
                    } else {
                        $return = 'last';
                    }
                }
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            return $return;
        }
    
        private function getLinksDesc($parentId, $collection)
        {
    
            $db = new Database();
    
    
            $query = 'SELECT res_child FROM res_linked, res_letterbox WHERE coll_id=? AND res_parent=? and res_letterbox.res_id = res_child and status != \'DEL\'';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $stmt = $db->query($query, array($collection, $parentId));
            if ($stmt) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                $i = 0;
                $links = '';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                while ($row = $stmt->fetchObject()) {
                    $links .= $row->res_child.'||';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                }
                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 Database();
    
    
            $query = 'SELECT res_parent FROM res_linked, res_letterbox WHERE coll_id=? AND res_child=? and res_letterbox.res_id = res_parent and status != \'DEL\'';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $stmt = $db->query($query, array($collection, $parentId));
            if ($stmt) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                $i = 0;
                $links = '';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                while ($row = $stmt->fetchObject()) {
                    $links .= $row->res_parent.'||';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                }
                if ($i > 0) {
                    $return = substr($links, 0, -2);
                }
            } else {
                $return = 'Problème lors de la requête : '.$query;
            }
    
            return $return;
        }
    
        public function getStatus($status)
        {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $db = new Database();
    
    
            $query = 'SELECT label_status, img_filename FROM status WHERE id = ?';
            $stmt = $db->query($query, array($status));
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if ($stmt) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                $i = 0;
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                }
            }
    
            return $return;
        }
    
        public function nbDirectLink($id, $collection, $sens)
        {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $db = new Database();
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if ($sens == 'desc' || $sens == 'all') {
    
                $query = 'SELECT res_child FROM res_linked, res_letterbox WHERE coll_id=? AND res_parent=? AND res_letterbox.res_id = res_child AND status != \'DEL\'';
    
                $stmt = $db->query($query, array($collection, $id));
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                if ($stmt) {
                    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                    }
                }
            }
            if ($sens == 'asc' || $sens == 'all') {
    
                $query = 'SELECT res_parent FROM res_linked, res_letterbox WHERE coll_id=? AND res_child=? AND res_letterbox.res_id = res_parent AND status != \'DEL\'';
    
                $stmt = $db->query($query, array($collection, $id));
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                if ($stmt) {
                    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                    }
                }
            }
    
            return $i;
        }
    
    
        public function getAltIdentifier($resId)
        {
    
            $db = new Database();
    
            $altIdentifierRequest = 'SELECT alt_identifier FROM res_letterbox where res_id = ?';
    
            $stmt = $db->query($altIdentifierRequest, array($resId));
            while ($altIdentifierResult = $stmt->fetchObject()) {
                $altIdentifier = $altIdentifierResult->alt_identifier;
            }
    
            return $altIdentifier;
    
        }
    
        public function getAltIdentifierConcatened($array)
        {
    
            $_SESSION['chronoNumber'] = '';
            for ($j = 0; $j < count($array); ++$j) {
                $_SESSION['chronoNumber'] .= $this->getAltIdentifier($array[$j]).', ';
            }
    
            return substr($_SESSION['chronoNumber'], 0, -2);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    }