Пример #1
0
 function ItemModelId($path)
 {
     /* find pol, sol and the type of item */
     list($pol_id, $sol_id, $rest) = sscanf($path, "/opt/xplico/pol_%d/sol_%d/%s");
     $type = strtok($rest, '/');
     /* set sol id and pol id to avoid error permision in the controller */
     $this->Session->write('pol', $pol_id);
     $this->Session->write('sol', $sol_id);
     /* controller and id */
     $control = null;
     $id = null;
     switch ($type) {
         case 'http':
             /* load model */
             $Feed = new Feed_xml();
             /* find id */
             $control = 'Feed_xml';
             $conditions = array('Feed_xml.rs_body' => $path);
             $param = array('recursive' => 0, 'fields' => array('Feed_xml.id'), 'conditions' => $conditions);
             $id = $Feed->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $Web = new Web();
                 /* find id */
                 $control = 'Web';
                 $conditions = array("or" => array('Web.rq_header' => $path, 'Web.rs_header' => $path, 'Web.rq_body' => $path, 'Web.rs_body' => $path));
                 $param = array('recursive' => 0, 'fields' => array('Web.id'), 'conditions' => $conditions);
                 $id = $Web->find('first', $param);
             }
             break;
         case 'fbwchat':
             /* load model */
             $Fbc = new Fbchat();
             /* find id */
             $control = 'Fbchat';
             $conditions = array('Fbchat.chat' => $path);
             $param = array('recursive' => 0, 'fields' => array('Fbchat.id'), 'conditions' => $conditions);
             $id = $Fbc->find('first', $param);
             break;
         case 'ftp':
             /* load model */
             $Ftp = new Ftp_file();
             /* find id */
             $control = 'Ftp_file';
             $conditions = array('Ftp_file.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Ftp_file.id'), 'conditions' => $conditions);
             $id = $Ftp->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $Ftp = new Ftp();
                 /* find id */
                 $control = 'Ftp';
                 $conditions = array('Ftp.cmd_path' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Ftp.id'), 'conditions' => $conditions);
                 $id = $Ftp->find('first', $param);
             }
             break;
         case 'ipp':
         case 'pjl':
             /* load model */
             $Pjl = new Pjl();
             /* find id */
             $control = 'Pjl';
             $conditions = array("or" => array('Pjl.pcl_path' => $path, 'Pjl.pdf_path' => $path));
             $param = array('recursive' => 0, 'fields' => array('Pjl.id'), 'conditions' => $conditions);
             $id = $Pjl->find('first', $param);
             break;
         case 'mail':
             /* load model */
             $Mail = new Email();
             /* find id */
             $control = 'Email';
             $conditions = array('Email.mime_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Email.id'), 'conditions' => $conditions);
             $id = $Mail->find('first', $param);
             break;
         case 'mms':
             /* load model */
             $Mms = new Mmscontent();
             /* find id */
             $control = 'Mmscontent';
             $conditions = array('Mmscontent.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Mmscontent.id'), 'conditions' => $conditions);
             $id = $Mms->find('first', $param);
             break;
         case 'nntp':
             /* load model */
             $Nntp = new Nntp_article();
             /* find id */
             $control = 'Nntp_article';
             $conditions = array('Nntp_article.mime_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Nntp_article.id'), 'conditions' => $conditions);
             $id = $Nntp->find('first', $param);
             break;
         case 'telnet':
             /* load model */
             $Teln = new Telnet();
             /* find id */
             $control = 'Telnet';
             $conditions = array('Telnet.cmd' => $path);
             $param = array('recursive' => 0, 'fields' => array('Telnet.id'), 'conditions' => $conditions);
             $id = $Teln->find('first', $param);
             break;
         case 'tftp':
             /* load model */
             $Tftp = new Tftp_file();
             $control = 'Tftp_file';
             $conditions = array('Tftp_file.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Tftp_file.id'), 'conditions' => $conditions);
             $id = $Tftp->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $Tftp = new Tftp();
                 /* find id */
                 $control = 'Tftp';
                 $conditions = array('Tftp.cmd_path' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Tftp.id'), 'conditions' => $conditions);
                 $id = $Tftp->find('first', $param);
             }
             break;
         case 'sip':
             /* load model */
             $mdl = new Sip();
             $control = 'sips';
             $conditions = array('Sip.commands' => $path);
             $param = array('recursive' => 0, 'fields' => array('Sip.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             if ($id == null) {
                 $conditions = array('Sip.ucaller' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Sip.id'), 'conditions' => $conditions);
                 $id = $mdl->find('first', $param);
                 if ($id == null) {
                     $conditions = array('Sip.ucalled' => $path);
                     $param = array('recursive' => 0, 'fields' => array('Sip.id'), 'conditions' => $conditions);
                     $id = $mdl->find('first', $param);
                 }
             }
             break;
         case 'webmail':
             /* load model */
             $mdl = new Webmail();
             $control = 'webmails';
             $conditions = array('Webmail.mime_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Webmail.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'httpfile':
             /* load model */
             $mdl = new Httpfile();
             $control = 'httpfile';
             $conditions = array('Httpfile.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Httpfile.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'grbudp':
             /* load model */
             $mdl = new Unknow();
             $control = 'unknows';
             $conditions = array('Unknow.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'grbtcp':
             /* load model */
             $mdl = new Unknow();
             $control = 'unknows';
             $conditions = array('Unknow.file_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'rtp':
             /* load model */
             $mdl = new Rtp();
             $control = 'rtps';
             $conditions = array('Rtp.ucaller' => $path);
             $param = array('recursive' => 0, 'fields' => array('Rtp.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             if ($id == null) {
                 $conditions = array('Rtp.ucalled' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Rtp.id'), 'conditions' => $conditions);
                 $id = $mdl->find('first', $param);
             }
             break;
         case 'irc':
             /* load model */
             $mdl = new Irc();
             $control = 'ircs';
             $conditions = array('Irc.cmd_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Irc.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             if ($id == null) {
                 /* load model */
                 $mdl = new Irc_channel();
                 $control = 'ircs';
                 $conditions = array('Irc_channel.channel_path' => $path);
                 $param = array('recursive' => 0, 'fields' => array('Irc_channel.id'), 'conditions' => $conditions);
                 $id = $mdl->find('first', $param);
             }
             break;
         case 'paltalk_exp':
             /* load model */
             $mdl = new Paltalk_exp();
             $control = 'paltalk_exps';
             $conditions = array('Paltalk_exp.channel_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Paltalk_exp.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'paltalk':
             /* load model */
             $mdl = new Paltalk_room();
             $control = 'paltalk_rooms';
             $conditions = array('Paltalk_room.room_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Paltalk_room.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
         case 'msn':
             /* load model */
             $mdl = new Msn_chat();
             $control = 'msn_chats';
             $conditions = array('Msn_chat.chat_path' => $path);
             $param = array('recursive' => 0, 'fields' => array('Msn_chat.id'), 'conditions' => $conditions);
             $id = $mdl->find('first', $param);
             break;
     }
     if ($id != null) {
         return array('model' => $control, 'id' => $id[$control]['id']);
     }
     return null;
 }