[ PHPXref.com ] [ Generated: Sun Jul 20 21:17:54 2008 ] [ Zoph 0.5.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/php/ -> user.inc.php (source)

   1  <?php
   2  
   3  /*
   4   * A class representing a user of Zoph.
   5   *
   6   * This file is part of Zoph.
   7   *
   8   * Zoph is free software; you can redistribute it and/or modify
   9   * it under the terms of the GNU General Public License as published by
  10   * the Free Software Foundation; either version 2 of the License, or
  11   * (at your option) any later version.
  12   * 
  13   * Zoph is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16   * GNU General Public License for more details.
  17   * You should have received a copy of the GNU General Public License
  18   * along with Zoph; if not, write to the Free Software
  19   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20   */
  21  class user extends zoph_table {
  22  
  23      var $person;
  24      var $prefs;
  25      var $crumbs;
  26      var $lang; // holds translations
  27  
  28      function user($id = 0) {
  29          parent::zoph_table("users", array("user_id"), array("user_name"));
  30          $this->set("user_id", $id);
  31      }
  32  
  33      function insert() {
  34          parent::insert();
  35          $this->prefs = new prefs($this->get("user_id"));
  36          $this->prefs->insert();
  37      }
  38  
  39      function delete() {
  40          parent::delete(null, array("prefs"));
  41      }
  42  
  43      function lookup_person() {
  44          $this->person = new person($this->get("person_id"));
  45          $this->person->lookup();
  46      }
  47  
  48      function lookup_prefs() {
  49          $this->prefs = new prefs($this->get("user_id"));
  50          $this->prefs->lookup();
  51      }
  52  
  53      function is_admin() {
  54          return $this->get("user_class") == 0;
  55      }
  56  
  57      function get_lastnotify() {
  58          return $this->get("lastnotify");
  59      }
  60  
  61      function get_album_permissions($album_id) {
  62          $ap = new album_permissions($this->get("user_id"), $album_id);
  63          if ($ap->lookup()) {
  64              return $ap;
  65          }
  66  
  67          return null;
  68      }
  69  
  70  
  71      function get_permissions_for_photo($photo_id) {
  72  
  73          // do ordering to grab entry with most permissions
  74          $sql =
  75              "select ap.* from " .
  76              DB_PREFIX . "photo_albums as pa, " .
  77              DB_PREFIX . "album_permissions as ap, " .
  78              DB_PREFIX . "photos as ph " .
  79              "where ap.user_id = '" . escape_string($this->get("user_id")) . "'".
  80              " and ap.album_id = pa.album_id" .
  81              " and pa.photo_id = ph.photo_id" .
  82              " and ph.photo_id = '" . escape_string($photo_id) . "'" .
  83              " and ap.access_level >= ph.level " .
  84              "order by ap.access_level desc, writable desc " .
  85              "limit 0, 1";
  86  
  87          $aps = get_records_from_query("album_permissions", $sql);
  88          if ($aps && sizeof($aps) >= 1) {
  89              return $aps[0];
  90          }
  91  
  92          return null;
  93      }
  94  
  95      function get_display_array() {
  96          $da = array(
  97              translate("username") => $this->get("user_name"),
  98              translate("person") => get_link("person", $this->get("person_id")),
  99              translate("class") =>
 100                  $this->get("user_class") == 0 ? "Admin" : "User",
 101              translate("can browse people") => $this->get("browse_people") == 1
 102                  ? translate("Yes") : translate("No"),
 103              translate("can browse places") => $this->get("browse_places") == 1
 104                  ? translate("Yes") : translate("No"),
 105              translate("can view details of people") =>
 106                  $this->get("detailed_people") == 1
 107                  ? translate("Yes") : translate("No"),
 108              translate("can view details of places") =>
 109                  $this->get("detailed_places") == 1
 110                  ? translate("Yes") : translate("No"),
 111              translate("can import") =>
 112                  $this->get("import") == 1
 113                  ? translate("Yes") : translate("No"),
 114              translate("last login") =>
 115                  $this->get("lastlogin"),
 116              translate("last ip address") =>
 117                  $this->get("lastip"));
 118  
 119          if ($this->get("lightbox_id")) {
 120              $lightbox = new album($this->get("lightbox_id"));
 121              $lightbox->lookup();
 122  
 123              if ($lightbox->get("album")) {
 124                  $da[translate("lightbox album")] = $lightbox->get("album");
 125              }
 126          }
 127  
 128          return $da;
 129      }
 130  
 131      function load_language($force = 0) {
 132  
 133          global $HTTP_ACCEPT_LANGUAGE;
 134  
 135          if (!$force && $this->lang != null) {
 136              return $this->lang;
 137          }
 138  
 139          if ($this->prefs != null && $this->prefs->get("language") != null) {
 140              $iso = $this->prefs->get("language");
 141  
 142              // instead of lang_exists() which requires the language name
 143              if (file_exists(LANG_DIR . '/' . $iso)) {
 144                  $application_lang = "$iso";
 145              }
 146          }
 147  
 148          // check browser list if there is no pref (or an invalid one)
 149          if (!isset($application_lang) && isset($HTTP_ACCEPT_LANGUAGE)) {
 150              $isotab = explode(",", $HTTP_ACCEPT_LANGUAGE);
 151  
 152              for ($i = 0; $i < count($isotab) && !isset($application_lang); $i++) {
 153                  $iso = substr(trim($isotab[$i]), 0, 2);
 154  
 155                  // instead of lang_exists (which requires the language name
 156                  if (file_exists(LANG_DIR . '/' . $iso)) {
 157                      $application_lang = "$iso";
 158                  }
 159              }
 160          }
 161  
 162          // default to English
 163          if(!isset($application_lang)) {
 164            $application_lang = "en";
 165          }
 166  
 167          $this->lang = new rtplang("lang", "en", "en", $application_lang);
 168          return $this->lang;
 169      }
 170  
 171      function add_crumb($title, $link) {
 172          $numCrumbs = count($this->crumbs);
 173          if ($numCrumbs == 0 || (!strpos($link, "_crumb="))) {
 174  
 175              // if title is the same remove last and add new
 176              if ($numCrumbs > 0 &&
 177                  strpos($this->crumbs[$numCrumbs - 1], ">$title<")) {
 178  
 179                  $this->eat_crumb();
 180              }
 181              else {
 182                  $numCrumbs++;
 183              }
 184  
 185              $question = strpos($link, "?");
 186              if ($question > 0) {
 187                  $link =
 188                      substr($link, 0, $question) ."?_crumb=$numCrumbs&amp;" .
 189                      substr($link, $question + 1);
 190              }
 191              else {
 192                  $link .= "?_crumb=$numCrumbs";
 193              }
 194  
 195              $this->crumbs[] = "<a href=\"$link\">$title</a>";
 196          }
 197      }
 198  
 199      function eat_crumb($num = -1) {
 200          if ($this->crumbs && count($this->crumbs) > 0) {
 201              if ($num < 0) { $num = count($this->crumbs) - 1; }
 202              $this->crumbs = array_slice($this->crumbs, 0, $num);
 203          }
 204      }
 205  
 206      function get_last_crumb() {
 207          if ($this->crumbs && count($this->crumbs) > 0) {
 208              return html_entity_decode($this->crumbs[count($this->crumbs) - 1]);
 209          }
 210      }
 211  
 212  }
 213  
 214  function get_users($order = "user_name") {
 215      return get_records("user", $order);
 216  }
 217  
 218  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]