Beispiel #1
0
 /**
  * Get all the link related to module based on type
  * @param Integer Module ID
  * @param mixed String or List of types to select 
  * @param Map Key-Value pair to use for formating the link url
  */
 static function getAllByType($tabid, $type = false, $parameters = false)
 {
     $adb = PearDatabase::getInstance();
     $current_user = vglobal('current_user');
     self::__initSchema();
     $multitype = false;
     if ($type) {
         // Multiple link type selection?
         if (is_array($type)) {
             $multitype = true;
             if ($tabid === self::IGNORE_MODULE) {
                 $sql = 'SELECT * FROM vtiger_links WHERE linktype IN (' . Vtiger_Utils::implodestr('?', count($type), ',') . ') ';
                 $params = $type;
                 $permittedTabIdList = getPermittedModuleIdList();
                 if (count($permittedTabIdList) > 0 && $current_user->is_admin !== 'on') {
                     array_push($permittedTabIdList, 0);
                     // Added to support one link for all modules
                     $sql .= ' and tabid IN (' . Vtiger_Utils::implodestr('?', count($permittedTabIdList), ',') . ')';
                     $params[] = $permittedTabIdList;
                 }
                 $result = $adb->pquery($sql, array($adb->flatten_array($params)));
             } else {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE (tabid=? OR tabid=0) AND linktype IN (' . Vtiger_Utils::implodestr('?', count($type), ',') . ')', array($tabid, $adb->flatten_array($type)));
             }
         } else {
             // Single link type selection
             if ($tabid === self::IGNORE_MODULE) {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE linktype=?', array($type));
             } else {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE (tabid=? OR tabid=0) AND linktype=?', array($tabid, $type));
             }
         }
     } else {
         $result = $adb->pquery('SELECT * FROM vtiger_links WHERE tabid=?', array($tabid));
     }
     $strtemplate = new Vtiger_StringTemplate();
     if ($parameters) {
         foreach ($parameters as $key => $value) {
             $strtemplate->assign($key, $value);
         }
     }
     $instances = array();
     if ($multitype) {
         foreach ($type as $t) {
             $instances[$t] = array();
         }
     }
     while ($row = $adb->fetch_array($result)) {
         $skipLink = false;
         $instance = new self();
         $instance->initialize($row);
         if (!empty($row['handler_path']) && isFileAccessible($row['handler_path'])) {
             checkFileAccessForInclusion($row['handler_path']);
             require_once $row['handler_path'];
             $linkData = new Vtiger_LinkData($instance, $current_user);
             $ignore = call_user_func(array($row['handler_class'], $row['handler']), $linkData);
             if (!$ignore) {
                 self::log("Ignoring Link ... " . var_export($row, true));
                 continue;
             }
         }
         if ($parameters) {
             $instance->linkurl = $strtemplate->merge($instance->linkurl);
             $instance->linkicon = $strtemplate->merge($instance->linkicon);
         }
         if ($instance->linktype == 'LISTVIEWSIDEBARWIDGET' || $instance->linktype == 'DETAILVIEWSIDEBARWIDGET') {
             parse_str($instance->linkurl, $linkurl);
             if (isset($linkurl['module']) && !Users_Privileges_Model::isPermitted($linkurl['module'], 'DetailView')) {
                 $skipLink = true;
             }
         }
         if (!$skipLink) {
             if ($multitype) {
                 $instances[$instance->linktype][] = $instance;
             } else {
                 $instances[$instance->linktype] = $instance;
             }
         }
     }
     return $instances;
 }
Beispiel #2
0
 /**
  * Get all the link related to module based on type
  * @param Integer Module ID
  * @param mixed String or List of types to select 
  * @param Map Key-Value pair to use for formating the link url
  */
 static function getAllByType($tabid, $type = false, $parameters = false)
 {
     global $adb, $current_user;
     self::__initSchema();
     $multitype = false;
     $orderby = " order by linktype,sequence";
     if ($type) {
         // Multiple link type selection?
         if (is_array($type)) {
             $multitype = true;
             if ($tabid === self::IGNORE_MODULE) {
                 $sql = 'SELECT * FROM vtiger_links WHERE linktype IN (' . Vtiger_Utils::implodestr('?', count($type), ',') . ') ';
                 $params = $type;
                 $permittedTabIdList = getPermittedModuleIdList();
                 if (count($permittedTabIdList) > 0 && $current_user->is_admin !== 'on') {
                     $sql .= ' and tabid IN (' . Vtiger_Utils::implodestr('?', count($permittedTabIdList), ',') . ')';
                     $params[] = $permittedTabIdList;
                 }
                 $result = $adb->pquery($sql . $orderby, array($adb->flatten_array($params)));
             } else {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE tabid=? AND linktype IN (' . Vtiger_Utils::implodestr('?', count($type), ',') . ')' . $orderby, array($tabid, $adb->flatten_array($type)));
             }
         } else {
             // Single link type selection
             if ($tabid === self::IGNORE_MODULE) {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE linktype=?' . $orderby, array($type));
             } else {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE tabid=? AND linktype=?' . $orderby, array($tabid, $type));
             }
         }
     } else {
         $result = $adb->pquery('SELECT * FROM vtiger_links WHERE tabid=?' . $orderby, array($tabid));
     }
     $strtemplate = new Vtiger_StringTemplate();
     if ($parameters) {
         foreach ($parameters as $key => $value) {
             $strtemplate->assign($key, $value);
         }
     }
     $instances = array();
     if ($multitype) {
         foreach ($type as $t) {
             $instances[$t] = array();
         }
     }
     while ($row = $adb->fetch_array($result)) {
         $instance = new self();
         $instance->initialize($row);
         if (!empty($row['handler_path']) && isFileAccessible($row['handler_path'])) {
             checkFileAccessForInclusion($row['handler_path']);
             require_once $row['handler_path'];
             $linkData = new Vtiger_LinkData($instance, $current_user);
             $ignore = call_user_func(array($row['handler_class'], $row['handler']), $linkData);
             if (!$ignore) {
                 self::log("Ignoring Link ... " . var_export($row, true));
                 continue;
             }
         }
         if ($parameters) {
             $instance->linkurl = $strtemplate->merge($instance->linkurl);
             $instance->linkicon = $strtemplate->merge($instance->linkicon);
         }
         if ($multitype) {
             $instances[$instance->linktype][] = $instance;
         } else {
             $instances[] = $instance;
         }
     }
     return $instances;
 }
Beispiel #3
0
 /**
  * Get all the link related to module based on type
  * @param Integer Module ID
  * @param mixed String or List of types to select 
  * @param Map Key-Value pair to use for formating the link url
  */
 static function getAllByType($tabid, $type = false, $parameters = false)
 {
     global $adb, $current_user;
     self::__initSchema();
     $multitype = false;
     if ($type) {
         // Multiple link type selection?
         if (is_array($type)) {
             $multitype = true;
             if ($tabid === self::IGNORE_MODULE) {
                 $sql = 'SELECT * FROM vtiger_links WHERE linktype IN (' . Vtiger_Utils::implodestr('?', count($type), ',') . ') ';
                 $params = $type;
                 $permittedTabIdList = getPermittedModuleIdList();
                 if (count($permittedTabIdList) > 0 && $current_user->is_admin !== 'on') {
                     $sql .= ' and tabid IN (' . Vtiger_Utils::implodestr('?', count($permittedTabIdList), ',') . ')';
                     $params[] = $permittedTabIdList;
                 }
                 $result = $adb->pquery($sql, array($adb->flatten_array($params)));
             } else {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE tabid=? AND linktype IN (' . Vtiger_Utils::implodestr('?', count($type), ',') . ')', array($tabid, $adb->flatten_array($type)));
             }
         } else {
             // Single link type selection
             if ($tabid === self::IGNORE_MODULE) {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE linktype=?', array($type));
             } else {
                 $result = $adb->pquery('SELECT * FROM vtiger_links WHERE tabid=? AND linktype=?', array($tabid, $type));
             }
         }
     } else {
         $result = $adb->pquery('SELECT * FROM vtiger_links WHERE tabid=?', array($tabid));
     }
     $strtemplate = new Vtiger_StringTemplate();
     if ($parameters) {
         foreach ($parameters as $key => $value) {
             $strtemplate->assign($key, $value);
         }
     }
     $instances = array();
     if ($multitype) {
         foreach ($type as $t) {
             $instances[$t] = array();
         }
     }
     while ($row = $adb->fetch_array($result)) {
         $instance = new self();
         $instance->initialize($row);
         if ($parameters) {
             $instance->linkurl = $strtemplate->merge($instance->linkurl);
             $instance->linkicon = $strtemplate->merge($instance->linkicon);
         }
         if ($multitype) {
             $instances[$instance->linktype][] = $instance;
         } else {
             $instances[] = $instance;
         }
     }
     return $instances;
 }