[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/projectmanager/inc/ -> class.uipricelist.inc.php (source)

   1  <?php
   2  /**************************************************************************\
   3  * eGroupWare - ProjectManager - Pricelist user interface                   *
   4  * http://www.egroupware.org                                                *
   5  * Written and (c) 2005 by Ralf Becker <RalfBecker@outdoor-training.de>     *
   6  * --------------------------------------------                             *
   7  *  This program is free software; you can redistribute it and/or modify it *
   8  *  under the terms of the GNU General Public License as published by the   *
   9  *  Free Software Foundation; either version 2 of the License, or (at your  *
  10  *  option) any later version.                                              *
  11  \**************************************************************************/
  12  
  13  /* $Id: class.uipricelist.inc.php 20452 2006-03-07 21:56:22Z ralfbecker $ */
  14  
  15  include_once (EGW_INCLUDE_ROOT.'/projectmanager/inc/class.bopricelist.inc.php');
  16  include_once (EGW_INCLUDE_ROOT.'/etemplate/inc/class.uietemplate.inc.php');
  17  
  18  /**
  19   * Pricelist user interface of the projectmanager
  20   *
  21   * @package projectmanager
  22   * @author RalfBecker-AT-outdoor-training.de
  23   * @copyright (c) 2005 by RalfBecker-AT-outdoor-training.de
  24   * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
  25   */
  26  class uipricelist extends bopricelist
  27  {
  28      var $public_functions = array(
  29          'index' => true,
  30          'view'  => true,
  31          'edit'  => true,
  32      );
  33      var $billable_lables = array('bookable','billable');
  34      /**
  35       * Constructor, calls the constructor of the extended class
  36       *
  37       * @param int $pm_id project to use
  38       */
  39  	function uipricelist($pm_id=null)
  40      {
  41          if (!is_null($pm_id) || isset($_REQUEST['pm_id']))
  42          {
  43              if (is_null($pm_id)) $pm_id = (int) $_REQUEST['pm_id'];
  44              $GLOBALS['egw']->session->appsession('pm_id','projectmanager',$pm_id);
  45          }
  46          else
  47          {
  48              $pm_id = (int) $GLOBALS['egw']->session->appsession('pm_id','projectmanager');
  49          }
  50          $this->bopricelist($pm_id);    // sets $this->pm_id
  51      }
  52      
  53  	function view()
  54      {
  55          return $this->edit(null,true);
  56      }
  57      
  58  	function edit($content=null,$view=false,$msg='')
  59      {
  60          $tpl =& new etemplate('projectmanager.pricelist.edit');
  61          $tabs = 'price|project|description';
  62          
  63          if (!is_array($content))
  64          {
  65              if (($pl_id = (int) $_GET['pl_id']) && $this->read(array(
  66                  'pl_id' => $pl_id,
  67                  'pm_id' => $this->pm_id ? array($this->pm_id,0) : 0,
  68              )))
  69              {
  70                  
  71                  // perms are checked later, see view_...prices
  72              }
  73              else    // add new price
  74              {
  75                  $pl_id = 0;
  76                  $view = false;
  77                  $this->data = array(
  78                      'prices' => array(),
  79                      'project_prices' => array(),
  80                      'pm_id' => $this->pm_id,
  81                  );
  82              }
  83              // no READ or EDIT/ADD rights ==> close the popup
  84              if (!$this->check_acl($view ? EGW_ACL_READ : EGW_ACL_EDIT) && 
  85                  !($this->pm_id && $this->check_acl($view ? EGW_ACL_READ : EGW_ACL_EDIT,$this->pm_id)))
  86              {
  87                  $js = "alert('".lang('Permission denied !!!')."'); window.close();";
  88                  $GLOBALS['egw']->common->egw_header();
  89                  echo "<script>\n$js\n</script>\n";
  90                  $GLOBALS['egw']->common->egw_exit();
  91              }
  92              if (count($this->data['project_prices'])) $content[$tabs] = 'project';    // open project tab
  93              $pm_id = count($this->data['project_prices']) ? $this->data['project_prices'][0]['pm_id'] : $this->pm_id;
  94          }
  95          else
  96          {
  97              $this->data = $content;
  98              foreach(array('view','button','delete_price','delete_project_price',$tabs) as $key)
  99              {
 100                  unset($this->data[$key]);
 101              }
 102              $pl_id = $content['pl_id'];
 103              $pm_id = $content['pm_id'];
 104              // copy only non-empty and not deleted prices to $this->data[*prices]
 105              foreach(array('prices' => 1,'project_prices' => 3) as $name => $row)
 106              {
 107                  $this->data[$name] = array();
 108                  $delete =& $content[$name == 'prices' ? 'delete_price' : 'delete_project_price'];
 109                  while (isset($content[$name][$row]))
 110                  {
 111                      $price = $content[$name][$row];
 112                      if ($price['pl_price'] && !$delete[$row])
 113                      {
 114                          $this->data[$name][] = $price;
 115                      }
 116                      ++$row;
 117                  }
 118              }
 119              if (!$this->data['pl_unit']) $this->data['pl_unit'] = lang('h');
 120  
 121              list($button) = @each($content['button']);
 122              switch($button)
 123              {
 124                  case 'save':
 125                  case 'apply':
 126                      if (!($err = $this->save()))
 127                      {
 128                          $msg = lang('Price saved');
 129                      }
 130                      else
 131                      {
 132                          $msg = lang('Error: saving the price (%1) !!!',$err);
 133                          $button = 'apply';    // dont close the window
 134                      }
 135                      $js = "window.opener.location.href='".$GLOBALS['egw']->link('/index.php',array(
 136                          'menuaction' => 'projectmanager.uipricelist.index',
 137                          'msg' => $msg,
 138                      ))."';";
 139                      if ($button == 'apply') break;
 140                      // fall through
 141                  case 'cancel':
 142                      $js .= 'window.close();';
 143                      echo '<html><body onload="'.$js.'"></body></html>';
 144                      $GLOBALS['egw']->common->egw_exit();
 145                      break;
 146                      
 147                  case 'edit':
 148                      $view = false;    // acl is ensured later, see $view_*prices
 149                      break;
 150              }
 151          }
 152          $view_prices = $view || count($this->data['prices']) && !$this->check_acl(EGW_ACL_EDIT);
 153          $view_project_prices = $view || !$this->check_acl(EGW_ACL_EDIT,$this->pm_id);
 154          $view = $view || $view_prices && $view_project_prices;    // nothing to edit => no rights
 155  
 156          $content = $this->data + array(
 157              'msg' => $msg,
 158              'js'  => $js ? "<script>\n".$js."\n</script>" : '',
 159              'view' => $view,
 160              'view_prices' => $view_prices,
 161              'view_project_prices' => $view_project_prices,
 162              $tabs => $content[$tabs],
 163          );
 164          // adjust index and add empty price-lines for adding new prices
 165          $content['prices'] = array_merge(array(1),$view_prices ? array() : array(array('pl_price'=>'')),$this->data['prices']);
 166          $content['project_prices'] = array_merge(array(1,2,3),$view_project_prices ? array() : array(array('pl_price'=>'')),$this->data['project_prices']);
 167  
 168          $preserv = $this->data + array(
 169              'view'  => $view,
 170          );
 171          if (!$this->data['pm_id']) $preserv['pm_id'] = $this->pm_id;
 172  
 173          $readonlys = array(
 174              'button[delete]' => !$pl_id || !$this->check_acl(EGW_ACL_EDIT_BUDGET,$pl_id),
 175          );
 176          // preserv the "real" prices, with there new keys
 177          foreach(array('prices','project_prices') as $name)
 178          {
 179              unset($preserv[$name]);
 180              foreach($content[$name] as $key => $price)
 181              {
 182                  if (is_array($price) && count($price) > 1)
 183                  {
 184                      $preserv[$name][$key] = $price;
 185                  }
 186              }
 187          }
 188          // set general data and price readonly, if $view or price belongs to general pricelist and no edit there
 189          if ($view || count($this->data['prices']) && !$this->check_acl(EGW_ACL_EDIT))
 190          {
 191              foreach($this->db_cols as $name => $data)
 192              {
 193                  $readonlys[$name] = true;
 194              }
 195              for($n = 0; $n <= count($this->data['prices']); ++$n)
 196              {
 197                  $readonlys['prices['.(1+$n).'][pl_price]'] = 
 198                  $readonlys['prices['.(1+$n).'][pl_validsince]'] = true;
 199              }
 200          }
 201          // set project-spez. prices readonly, if view or no edit-rights there 
 202          if ($view || !$this->check_acl(EGW_ACL_EDIT,$this->pm_id))
 203          {
 204              foreach(array('pl_billable','pl_customertitle') as $name)
 205              {
 206                  $readonlys[$name] = true;
 207              }
 208              for($n = 0; $n <= count($this->data['project_prices']); ++$n)
 209              {
 210                  $readonlys['project_prices['.(3+$n).'][pl_price]'] = 
 211                  $readonlys['project_prices['.(3+$n).'][pl_validsince]'] = true;
 212              }
 213          }
 214          $readonlys['button[save]'] = $readonlys['button[apply]'] = $view;
 215          $readonlys['button[edit]'] = !$view || !$this->check_acl(EGW_ACL_EDIT) && !$this->check_acl(EGW_ACL_EDIT,$this->pm_id);
 216          
 217          if (!$this->pm_id)    // no project tab for the general pricelist
 218          {
 219              $readonlys[$tabs]['project'] = true;
 220          }
 221          // no general price tab, if there are none and no rights to edit the general pricelist
 222          if (!count($this->data['prices']) && !$this->check_acl(EGW_ACL_EDIT))
 223          {
 224              $readonlys[$tabs]['price'] = true;
 225          }
 226          $GLOBALS['egw_info']['flags']['app_header'] = lang('projectmanager').' - '.
 227              ($view ? lang('View price') :  ($pl_id ? lang('Edit price') : lang('Add price'))) .
 228              ($this->pm_id ? ': ' . $this->project->data['pm_number'] . ': ' .$this->project->data['pm_title'] : '');
 229  
 230          //_debug_array($content);
 231          //_debug_array($readonlys);
 232          return $tpl->exec('projectmanager.uipricelist.edit',$content,array(
 233              'pl_billable' => $this->billable_lables,
 234          ),$readonlys,$preserv,2);
 235      }
 236      
 237      /**
 238       * query pricelist for nextmatch
 239       *
 240       * reimplemented from so_sql to disable action-buttons based on the acl and make some modification on the data
 241       *
 242       * @param array $query
 243       * @param array &$rows returned rows/cups
 244       * @param array &$readonlys eg. to disable buttons based on acl
 245       */
 246  	function get_rows(&$query,&$rows,&$readonlys)
 247      {
 248          $GLOBALS['egw']->session->appsession('pricelist','projectmanager',$query);
 249      
 250          if ($query['cat_id'])
 251          {
 252              $query['col_filter']['cat_id'] = $query['cat_id'];
 253          }
 254          if ($query['col_filter']['pm_id'] === '' || !$this->check_acl(EGW_ACL_READ,$query['col_filter']['pm_id']))
 255          {
 256              unset($query['col_filter']['pm_id']);
 257          }
 258          elseif ($query['col_filter']['pm_id'] != $this->pm_id)
 259          {
 260              $this->uipricelist($query['col_filter']['pm_id']);
 261          }
 262          if ($query['col_filter']['pl_billable'] === '') unset($query['col_filter']['pl_billable']);
 263  
 264          $total = parent::get_rows($query,$rows,$readonlys,true);
 265  
 266          $readonlys = array();
 267          foreach($rows as $n => $val)
 268          {
 269              $row =& $rows[$n];
 270              if (!$this->check_acl(EGW_ACL_EDIT) && !($this->pm_id && $this->check_acl(EGW_ACL_EDIT,$this->pm_id)))
 271              {
 272                  $readonlys["edit[$row[pl_id]]"] = true;
 273              }
 274              // we only delete prices from the shown pricelist, not inhirited ones or onces from the general list
 275              if ($row['pm_id'] != $this->pm_id || !$this->check_acl(EGW_ACL_EDIT,$this->pm_id))
 276              {
 277                  $readonlys["delete[$row[pm_id]:$row[pl_id]]"] = true;
 278              }
 279          }
 280          $rows['standard_only'] = !$this->pm_id;
 281  
 282          return $total;        
 283      }
 284  
 285  	function index($content=null,$msg='')
 286      {
 287          while (!$this->check_acl(EGW_ACL_READ,$this->pm_id))
 288          {
 289              if ($this->pm_id)    // try falling back to the general pricelist
 290              {
 291                  $GLOBALS['egw']->session->appsession('pm_id','projectmanager',$_REQUEST['pm_id'] = $this->pm_id = 0);
 292              }
 293              else
 294              {
 295                  $GLOBALS['egw']->redirect_link('/index.php',array(
 296                      'menuaction' => 'projectmanager.uiprojectmanager.index',
 297                      'msg' => lang('Permission denied !!!'),
 298                  ));
 299              }
 300          }
 301          $tpl =& new etemplate('projectmanager.pricelist.list');
 302  
 303          if (!is_array($content))
 304          {
 305              $content = array();
 306          }
 307          elseif($content['nm']['rows']['delete'])
 308          {
 309              list($id) = @each($content['nm']['rows']['delete']);
 310              list($pm_id,$pl_id) = explode(':',$id);
 311  
 312              if ($pl_id && $this->delete(array('pm_id' => $pm_id,'pl_id' => $pl_id)))
 313              {
 314                  $msg = lang('Price deleted');
 315              }
 316              else
 317              {
 318                  $msg = lang('Permission denied !!!');
 319              }
 320          }
 321          $content['msg'] = $msg ? $msg : $_GET['msg'];
 322          $content['nm'] = $GLOBALS['egw']->session->appsession('pricelist','projectmanager');
 323          if (!is_array($content['nm']))
 324          {
 325              $content['nm'] = array(
 326                  'get_rows'       =>    'projectmanager.uipricelist.get_rows',
 327                  'no_filter'      => true,
 328                  'no_filter2'     => true,
 329                  'order'          =>    'pl_title',// IO name of the column to sort after (optional for the sortheaders)
 330                  'sort'           =>    'DESC',// IO direction of the sort: 'ASC' or 'DESC'
 331              );
 332          }
 333          $content['nm']['col_filter']['pm_id'] = $this->pm_id;
 334  
 335          $GLOBALS['egw_info']['flags']['app_header'] = lang('projectmanager').' - '.($this->pm_id ? 
 336              lang('Pricelist') .': ' . $this->project->data['pm_number'] . ': ' .$this->project->data['pm_title'] : 
 337              lang('General pricelist'));
 338  
 339          $projects = array();
 340          foreach((array)$this->project->search(array(
 341              'pm_status' => 'active',
 342              'pm_id'     => $this->pm_id,        // active or the current one
 343          ),$this->project->table_name.'.pm_id AS pm_id,pm_number,pm_title','pm_number','','',False,'OR',false,array('pm_accounting_type' => 'pricelist')) as $project)
 344          {
 345              $projects[$project['pm_id']] = $project['pm_number'].': '.$project['pm_title'];
 346          }
 347          $projects[0] = lang('General pricelist');
 348          
 349          $readonlys = array(
 350              // show add button only, if user has rights to add a new price
 351              'add' => !$this->check_acl(EGW_ACL_EDIT,$this->pm_id),
 352          );
 353          return $tpl->exec('projectmanager.uipricelist.index',$content,array(
 354              'pl_billable' => $this->billable_lables,
 355              'pm_id' => $projects,
 356          ),$readonlys);
 357      }
 358  }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7