• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.perm.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00025 // TODO: this function collection must cleaned up!!! Many functions belong to other classes
00040 /*
00041 function getObject ($a_obj_id)
00042 {
00043 }*/
00044 
00045 /*
00050 function getObjectByReference ($a_ref_id)
00051 {
00052 }*/
00053 
00054 
00058 /*
00059 function copyObject ($a_obj_id)
00060 {
00061 }*/
00062 
00063 /*
00067 function deleteObject ($a_obj_id)
00068 {
00069 }*/
00070 
00082    /*
00083 function updateObject ($a_obj_id,$a_title,$a_desc,$a_len_title=MAXLENGTH_OBJ_TITLE,$a_len_desc=MAXLENGTH_OBJ_DESC,$a_dots=true)
00084 {
00085         global $ilias;
00086 
00087         if (!isset($a_obj_id))
00088         {
00089                 $message = "perm::updateObject(): No obj_id given!";
00090                 $ilias->raiseError($message,$ilias->error_obj->WARNING);        
00091         }
00092         
00093         if (empty($a_title))
00094         {
00095                 $message = "perm::updateObject(): No title given! A title is required!";
00096                 $ilias->raiseError($message,$ilias->error_obj->WARNING);        
00097         }
00098 
00099         // cut length of text
00100         $a_title = ilUtil::shortenText($a_title,$a_len_title,$a_dots);
00101         $_desc = ilUtil::shortenText($a_desc,$a_len_desc,$a_dots);
00102 
00103         $q = "UPDATE object_data ".
00104                  "SET ".
00105                  "title='".ilUtil::addSlashes($a_title)."',".
00106                  "description='".ilUtil::addSlashes($a_desc)."', ".
00107                  "last_update=now() ".
00108                  "WHERE obj_id='".$a_obj_id."'";
00109         $ilias->db->query($q);
00110 
00111         return true;
00112 }
00113 */
00114 
00115 
00124 function updateObjectValue($a_obj_id,$a_column,$a_value)
00125 {
00126         global $ilias;
00127         
00128         if (!isset($a_obj_id))
00129         {
00130                 $message = "perm::updateObjectValue(): No obj_id given!";
00131                 $ilias->raiseError($message,$ilias->error_obj->WARNING);        
00132         }
00133         
00134         if (!isset($a_column))
00135         {
00136                 $message = "perm::updateObjectValue(): No table column specified!";
00137                 $ilias->raiseError($message,$ilias->error_obj->WARNING);        
00138         }
00139 
00140         $q = "UPDATE object_data ".
00141                  "SET ".$a_column."='".ilUtil::addSlashes($a_value)."',".
00142                  "last_update=now() ".
00143                  "WHERE obj_id='".$a_id."'";
00144         $ilias->db->query($q);
00145         
00146         return true;
00147 }
00148 
00155 function fetchObjectData($a_row)
00156 {
00157         $arr = array (
00158                                         "obj_id"                => $a_row->obj_id,
00159                                         "ref_id"                => $a_row->ref_id,
00160                                         "type"                  => $a_row->type,
00161                                         "title"                 => $a_row->title,
00162                                         "description"   => $a_row->description, // for compability only
00163                                         "desc"                  => $a_row->description,
00164                                         "usr_id"                => $a_row->owner,       // compability
00165                                         "owner"                 => $a_row->owner,
00166                                         "create_date"   => $a_row->create_date,
00167                                         "last_update"   => $a_row->last_update,
00168                                         "last_login"    => $a_row->last_login,  // maybe senseless
00169                                         "assign"                => $a_row->assign,      // maybe senseless
00170                                         "protected"             => $a_row->protected,
00171                                         "parent"                => $a_row->parent       // role folder 
00172                                 );
00173 
00174         return $arr ? $arr : array();   // maybe senseless
00175 }
00176 
00177 
00188 function getObjectList ($a_obj_type = "",$a_order = "", $a_direction = "ASC", $a_offset = "",$a_limit = "")
00189 {
00190         global $ilias;
00191         
00192         // order
00193         if (!$a_order)
00194         {
00195                 $a_order = "title";
00196         }
00197         
00198         $order = "ORDER BY ".$a_order." ".$a_direction;
00199 
00200         // limit clause
00201         if ($a_limit && $a_offset)
00202         {
00203                 $limit_clause = " LIMIT ".$a_offset.",".$a_limit;
00204         }
00205 
00206         // where clause
00207         if ($a_obj_type)
00208         {
00209                 $where_clause = "WHERE type = '".$a_obj_type."' ";
00210         }
00211 
00212         $q = "SELECT * FROM object_data ".$where_clause.$order.$limit_clause;
00213         $r = $ilias->db->query($q);
00214 
00215         if ($r->numRows() > 0)
00216         {
00217                 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00218                 {
00219                         $arr[$row->obj_id] = fetchObjectData($row);
00220                 }
00221 
00222                 return $arr;
00223         }
00224 
00225         return false;
00226 }
00227 
00237 function getOperationList ($a_type = null)
00238  {
00239         global $ilias;
00240 
00241         $arr = array();
00242 
00243         if ($a_type)
00244         {
00245                 $q = "SELECT * FROM rbac_operations ".
00246                          "LEFT JOIN rbac_ta ON rbac_operations.ops_id = rbac_ta.ops_id ".
00247                          "LEFT JOIN object_data ON rbac_ta.typ_id = object_data.obj_id ".
00248                          "WHERE object_data.title='".$a_type."' AND object_data.type='typ' ".
00249                          "ORDER BY 'order' ASC"; 
00250         }
00251         else
00252         {
00253                 $q = "SELECT * FROM rbac_operations ".
00254                          "ORDER BY 'order' ASC";
00255         }
00256         
00257         $r = $ilias->db->query($q);
00258 
00259         while ($row = $r->fetchRow())
00260         {
00261                 $arr[] = array(
00262                                         "ops_id"        => $row[0],
00263                                         "operation"     => $row[1],
00264                                         "desc"          => $row[2],
00265                                         "class"         => $row[3],
00266                                         "order"         => $row[4]
00267                                         );
00268         }
00269 
00270         return $arr;
00271 }
00272 
00273 function groupOperationsByClass($a_ops_arr)
00274 {
00275         $arr = array();
00276 
00277         foreach ($a_ops_arr as $ops)
00278         {
00279                 $arr[$ops['class']][] = array ('ops_id' => $ops['ops_id'],
00280                                                                            'name'       => $ops['operation']
00281                                                                          );
00282         }
00283         
00284         return $arr; 
00285 }
00286 
00294 function createNewOperation ($a_operation,$a_description)
00295 {
00296         global $ilias;
00297 
00298         if (!isset($a_operation))
00299         {
00300                 $message = "perm::createNewOperation(): No operation name given!";
00301                 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00302         }
00303 
00304         // check if operation exists
00305         $ops_id = getOperationId($a_operation);
00306         // quit in case operation already exists
00307         if (!empty($ops_id))
00308         {
00309                 $message = "perm::createNewOperation(): An operation '".$a_operation."' is already defined!";
00310                 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00311         }
00312 
00313         $q = "INSERT INTO operations ".
00314                  "(operation,description) ".
00315                  "VALUES ".
00316                  "('".ilUtil::addSlashes($a_operation)."','".ilUtil::addSlashes($a_description)."')";
00317         $ilias->db->query($q);
00318 
00319         return $ilias->db->getLastInsertId();
00320 }
00321 
00328 function getOperationId($a_operation)
00329 {
00330         global $ilias;
00331 
00332         if (!isset($a_operation))
00333         {
00334                 $message = "perm::getOperationId(): No operation given!";
00335                 $ilias->raiseError($message,$ilias->error_obj->WARNING);        
00336         }
00337 
00338         $q = "SELECT DISTINCT ops_id FROM rbac_operations ".
00339                  "WHERE operation ='".$a_operation."'";             
00340         $row = $ilias->db->getRow($q);
00341 
00342         return $row->ops_id;
00343 }
00344 
00345 /*
00346 * get last insert id of a mysql query
00347 * @access       public
00348 * @return       integer last insert id
00349 */
00350 /*
00351 
00352 This function is deprecated !!!
00353 Use $ilDB->getLastInsertId()
00354 
00355 function getLastInsertId()
00356 {
00357         global $ilias;
00358 
00359         $r = $ilias->db->query("SELECT LAST_INSERT_ID()");
00360         $row = $r->fetchRow();
00361 
00362         return $row[0];
00363 }*/
00364 
00371 function isUserLoggedIn ()
00372 {
00373         global $ilias;
00374 
00375         $user_id = $ilias->account->getId();
00376 
00377         if (empty($user_id))
00378         {
00379                 return false;
00380         }
00381 
00382         return true;
00383 }
00384 
00392 function trimDeluxe ($a_text)
00393 {
00394         str_replace("\t"," ",$a_text);
00395 
00396         for ($i=0;$i<50;$i++)
00397         {
00398                 str_replace("  "," ",$a_text);
00399         }
00400 
00401         $a_text = trim($a_text);
00402 
00403         return $a_text;
00404 }
00405 
00409 /*
00410 function shortenText ($a_str, $a_len, $a_dots = "false")
00411 {
00412 }*/
00413 
00422 function loginExists($a_login,$a_user_id = 0)
00423 {
00424         global $ilias;
00425 
00426         if ($a_user_id == 0)
00427         {
00428                 $clause = "";
00429         }
00430         else
00431         {
00432                 $clause = "AND usr_id != '".$a_user_id."'";
00433         }
00434 
00435         $q = "SELECT DISTINCT login FROM usr_data ".
00436                  "WHERE login = '".ilUtil::stripSlashes($a_login)."' ".$clause;
00437         $r = $ilias->db->query($q);
00438         
00439         if ($r->numRows() == 1)
00440         {
00441                 return true;
00442         }
00443         
00444         return false;
00445 }
00446 
00455 function sendInfo($a_info = "",$a_keep = false)
00456 {
00457         global $tpl;
00458 
00459         if (!empty($a_info))
00460         {
00461                 $_SESSION["info"] = $a_info;
00462         }
00463         if (!empty($_SESSION["info"]))
00464         {
00465                 $tpl->addBlockFile("MESSAGE", "message", "tpl.message.html");
00466 #               $tpl->setCurrentBlock("message");
00467                 $tpl->setVariable("INFO",$_SESSION["info"]);
00468 #               $tpl->parseCurrentBlock();
00469         }
00470 
00471         if (!$a_keep)
00472         {
00473                 session_unregister("info");
00474         }
00475 }
00476 
00477 function infoPanel($a_keep = true)
00478 {
00479         global $tpl,$ilias,$lng;
00480 
00481         if (!empty($_SESSION["infopanel"]) and is_array($_SESSION["infopanel"]))
00482         {
00483                 $tpl->addBlockFile("INFOPANEL", "infopanel", "tpl.infopanel.html");
00484                 $tpl->setCurrentBlock("infopanel");
00485 
00486                 if (!empty($_SESSION["infopanel"]["text"]))
00487                 {
00488                         $link = "<a href=\"".$dir.$_SESSION["infopanel"]["link"]."\" target=\"".
00489                                 ilFrameTargetInfo::_getFrame("MainContent").
00490                                 "\">";
00491                         $link .= $lng->txt($_SESSION["infopanel"]["text"]);
00492                         $link .= "</a>";
00493                 }
00494 
00495                 // deactivated
00496                 if (!empty($_SESSION["infopanel"]["img"]))
00497                 {
00498                         $link .= "<td><a href=\"".$_SESSION["infopanel"]["link"]."\" target=\"".
00499                                 ilFrameTargetInfo::_getFrame("MainContent").
00500                                 "\">";
00501                         $link .= "<img src=\"".$ilias->tplPath.$ilias->account->prefs["skin"]."/images/".
00502                                 $_SESSION["infopanel"]["img"]."\" border=\"0\" vspace=\"0\"/>";
00503                         $link .= "</a></td>";
00504                 }
00505 
00506                 $tpl->setVariable("INFO_ICONS",$link);
00507                 $tpl->parseCurrentBlock();
00508         }
00509 
00510         //if (!$a_keep)
00511         //{
00512                         session_unregister("infopanel");
00513         //}
00514 }
00515 ?>

Generated on Fri Dec 13 2013 13:52:08 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1