Viewing file:      mo_crud.php (3.46 KB)      -rwxr-xr-x Select action/file-type:    (+) |   (+) |   (+) | Code (+) | Session (+) |   (+) | SDB (+) |   (+) |   (+) |   (+) |   (+) |   (+) |
 
<?php
 class Mo_crud extends CI_Model {
     function __construct() {
         parent::__construct();
     }
 
     function setCRUD($UsID,$gpid,$mnid) {
         $CI =& get_instance();
         $CI->load->model($CI->config->item("ums_folder").'m_umpermission','');
         $CI->load->model($CI->config->item("ums_folder").'m_umgpermission','');
 
         $X = 1;
         $C = 1;
         $R = 1;
         $U = 1;
         $D = 1;
         $oUp = $CI->m_umpermission->SearchByKey($UsID, $mnid);
 
         if ($oUp) {
             $X = $oUp['pmX'];
             $C = $oUp['pmC'];
             $R = $oUp['pmR'];
             $U = $oUp['pmU'];
             $D = $oUp['pmD'];
         } else {
             $oGp = $CI->m_umgpermission->SearchByKey($gpid, $mnid);
             if ($oGp) {
                 $X = $oGp['gpX'];
                 $C = $oGp['gpC'];
                 $R = $oGp['gpR'];
                 $U = $oGp['gpU'];
                 $D = $oGp['gpD'];
             }
         }
 
         return array('X' => $X, 'C' => $C, 'R' => $R, 'U' => $U, 'D' => $D);
 
     }
 
     function CRUD ($link, $linktype) {
         $UsID = $this->session->userdata('UsID');
         $gpid = $this->session->userdata('GpID');
         $mnid = $this->session->userdata('MnID');
 
         $crud = $this->setCRUD($UsID, $gpid, $mnid);
 
         $linktype = strtolower($linktype);
         if (strpos("crud", $linktype) === false) die("ชนิดของ Link ต้องเป็น CRUD เท่านั้น");
 
         $flg = false;
 
         if (($linktype == "c") and ($crud['C'] == 0))
              $flg = true;
         else if (($linktype == "r") and ($crud['R']  == 0)) 
             $flg = true;
         else if (($linktype == "u") and ($crud['U']  == 0))
             $flg = true;
         else if (($linktype == "d") and ($crud['D']  == 0)) 
             $flg = true;
         
         if ($flg == false) {
             return  $link;
         } else {
             $link = trim($link);
             $s = strtolower($link);
             //----------------------------------------------------------------
             //find image name
             //            $input="images/del.gif";
             //            $output = "images/delgrey.gif";        // use explode fn
             //            $this->createGreyFromGifJpg($input, $output);
             //---------------------------------------------------------------
             //rename imagename.gif to imagenamegrey.gif
             $pGif = strpos($s, ".gif");
             if ($pGif === false) {
             } else {
                 $ss = substr_replace($link, "grey", $pGif).substr($link, $pGif);
                 $link = $ss;
                 $s = strtolower($link);
             }
             //rename imagename.jpg to imagenamegrey.jpg
             $pJpg = strpos($s, ".jp");
             if ($pJpg === false) {
             } else {
                 $ss = substr_replace($link, "grey", $pJpg).substr($link, $pJpg);
                 $link = $ss;
                 $s = strtolower($link);
             }
             //add disabled to input tag
             $pos = strpos($s, "input");
             if ($pos === false) {
             } else {
                 $ss = substr_replace($link, "input disabled", $pos).substr($link, $pos+5);
                 $link = $ss;
                 $s = strtolower($link);
             }
             //change onclick-->onklick
             $pOnClick = strpos($s, "onclick");
             if ($pOnClick === false) {
             } else {
                 $ss = substr_replace($link, "onklick", $pOnClick).substr($link, $pOnClick+7);
                 $link = $ss;
                 $s = strtolower($link);
             }
             ////////////
             //disable tag A 
             $pHref = strpos($s, "href");
             if ($pHref === false) {
             } else {
                 $ss = substr_replace($link, "href1", $pHref).substr($link, $pHref+4);
                 $link = $ss;
                 $s = strtolower($link);
             }
             //disable text between tag A and not have tag img 
             $pImg = strpos($s, "<img")===false;
             if ($pImg === false) {
                 if (substr($s, 0, 2) == "<a") {
                     $p1 = strpos($link, ">");
                     $p2 = strpos($link, "</");
                     $ss = "<font color=#999999>".substr($link, $p1+1, $p2)."</font>";
                     $link = $ss;
                     $s = strtolower($link);
                 }
             }
             return $link;
         }
 
     }
 
 
 }
 ?>
  |