[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/timesheet/inc/ -> class.uitimesheet.inc.php (source)

   1  <?php
   2  /**************************************************************************\
   3  * eGroupWare - TimeSheet: 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.uitimesheet.inc.php 20961 2006-04-05 16:26:17Z ralfbecker $ */
  14  
  15  require_once (EGW_INCLUDE_ROOT.'/etemplate/inc/class.uietemplate.inc.php');
  16  require_once ('class.botimesheet.inc.php');
  17  
  18  /**
  19   * User interface object of the TimeSheet
  20   *
  21   * @package timesheet
  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 uitimesheet extends botimesheet
  27  {
  28      var $public_functions = array(
  29          'view' => true,
  30          'edit' => true,
  31          'index' => true,
  32      );
  33  
  34  	function uitimesheet()
  35      {
  36          $this->botimesheet();
  37      }
  38  
  39  	function view()
  40      {
  41          $this->edit(null,true);
  42      }
  43      
  44  	function edit($content = null,$view = false)
  45      {
  46          $tabs = 'general|notes|links';
  47  
  48          if (!is_array($content))
  49          {
  50              if ($view || (int)$_GET['ts_id'])
  51              {
  52                  if (!$this->read((int)$_GET['ts_id']))
  53                  {
  54                      $GLOBALS['egw']->common->egw_header();
  55                      echo "<script>alert('".lang('Permission denied!!!')."'); window.close();</script>\n";
  56                      $GLOBALS['egw']->common->egw_exit();
  57                  }
  58                  if (!$view && !$this->check_acl(EGW_ACL_EDIT))
  59                  {
  60                      $view = true;
  61                  }
  62              }
  63              else    // new entry
  64              {
  65                  $this->data = array(
  66                      'ts_start' => $this->today,
  67                      'ts_owner' => $GLOBALS['egw_info']['user']['account_id'],
  68                      'cat_id'   => (int) $_REQUEST['cat_id'],
  69                  );
  70              }
  71              $referer = preg_match('/menuaction=([^&]+)/',$_SERVER['HTTP_REFERER'],$matches) ? $matches[1] : 
  72                  (strstr($_SERVER['HTTP_REFERER'],'/infolog/index.php') ? 'infolog.uiinfolog.index' : TIMESHEET_APP.'.uitimesheet.index');
  73          }
  74          else
  75          {
  76              list($button) = @each($content['button']);
  77              $view = $content['view'];
  78              $referer = $content['referer'];
  79              $this->data = $content;
  80              foreach(array('button','view','referer',$tabs) as $key)
  81              {
  82                  unset($this->data[$key]);
  83              }
  84              switch($button)
  85              {
  86                  case 'edit':
  87                      if ($this->check_acl(EGW_ACL_EDIT)) $view = false;
  88                      break;
  89                      
  90                  case 'save':
  91                  case 'save_new':
  92                  case 'apply':
  93                      if (!$this->data['ts_quantity'])    // set the quantity (in h) from the duration (in min)
  94                      {
  95                          $this->data['ts_quantity'] = $this->data['ts_duration'] / 60.0;
  96                      }
  97                      if (!$this->data['ts_project']) $this->data['ts_project'] = $this->data['ts_project_blur'];
  98                      if (!$this->data['ts_title']) $this->data['ts_title'] = $this->data['ts_title_blur'];
  99  
 100                      if ($this->save() != 0)
 101                      {
 102                          $msg = lang('Error saving the entry!!!');
 103                          $button = '';
 104                      }
 105                      else
 106                      {
 107                          $msg = lang('Entry saved');
 108                          if ((int) $this->data['pm_id'] != (int) $this->data['old_pm_id'])
 109                          {
 110                              // update links accordingly
 111                              if ($this->data['pm_id'])
 112                              {
 113                                  $this->link->link(TIMESHEET_APP,$content['link_to']['to_id'],'projectmanager',$this->data['pm_id']);
 114                              }
 115                              if ($this->data['old_pm_id'])
 116                              {
 117                                  $this->link->unlink2(0,TIMESHEET_APP,$content['link_to']['to_id'],0,'projectmanager',$this->data['old_pm_id']);
 118                                  unset($this->data['old_pm_id']);
 119                              }
 120                          }
 121                          if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id']))
 122                          {
 123                              $this->link->link(TIMESHEET_APP,$this->data['ts_id'],$content['link_to']['to_id']);
 124                          }
 125                      }
 126                      $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',array(
 127                          'menuaction' => $referer,
 128                          'msg'        => $msg,
 129                      ))."';";
 130                      if ($button == 'apply') break;
 131                      if ($button == 'save_new')
 132                      {
 133                          // create a new entry
 134                          $this->data['ts_start'] += 60 * $this->data['ts_duration'];
 135                          foreach(array('ts_id','ts_title','ts_description','ts_duration','ts_quantity','ts_modified','ts_modifier') as $name)
 136                          {
 137                              unset($this->data[$name]);
 138                          }
 139                          break;
 140                      }
 141                      // fall-through for save
 142                  case 'delete':
 143                      if ($button == 'delete')
 144                      {
 145                          if ($this->delete())
 146                          {
 147                              $msg = lang('Entry deleted');
 148                              $js = "opener.location.href=opener.location.href+'&msg=$msg';";
 149                          }
 150                          else
 151                          {
 152                              $msg = lang('Error deleting the entry!!!');
 153                              break;    // dont close window
 154                          }
 155                      }
 156                      // fall-through for save
 157                  case 'cancel':
 158                      $js .= 'window.close();';
 159                      echo "<html>\n<body>\n<script>\n$js\n</script>\n</body>\n</html>\n";
 160                      $GLOBALS['egw']->common->egw_exit();
 161                      break;
 162              }
 163          }
 164          $preserv = $this->data + array(
 165              'view'    => $view,
 166              'referer' => $referer,
 167              'ts_title_blur' => $content['ts_title_blur'],
 168          );
 169          $content = array_merge($this->data,array(
 170              'msg'  => $msg,
 171              'view' => $view,
 172              $tabs  => $content[$tabs],
 173              'link_to' => array(
 174                  'to_id' => $this->data['ts_id'] || $button == 'save_new' ? $this->data['ts_id'] : $content['link_to']['to_id'],
 175                  'to_app' => TIMESHEET_APP,
 176              ),
 177              'js' => "<script>\n$js\n</script>\n",
 178              'ts_quantity_blur' => $this->data['ts_duration'] ? round($this->data['ts_duration'] / 60.0,3) : '',
 179          ));
 180          $links = array();
 181          // create links specified in the REQUEST (URL)
 182          if (!$this->data['ts_id'] && isset($_REQUEST['link_app']) && isset($_REQUEST['link_id']) && !is_array($content['link_to']['to_id']))
 183          {
 184              $link_ids = is_array($_REQUEST['link_id']) ? $_REQUEST['link_id'] : array($_REQUEST['link_id']);
 185              foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
 186              {
 187                  $link_id = $link_ids[$n];
 188                  if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id))    // gard against XSS
 189                  {
 190                      $this->link->link(TIMESHEET_APP,$content['link_to']['to_id'],$link_app,$link_id);
 191                      switch ($link_app)
 192                      {
 193                          case 'projectmanager':
 194                              $links[] = $link_id;
 195                              break;
 196                          case 'infolog':
 197                              $preserv['ts_title_blur'] = $this->link->title('infolog',$link_id);
 198                              break;
 199                      }
 200                  }
 201              }
 202          }
 203          elseif ($this->data['ts_id'])
 204          {
 205              $links = $this->link->get_links(TIMESHEET_APP,$this->data['ts_id'],'projectmanager');
 206          }
 207          $preserv['old_pm_id'] = array_shift($links);
 208          if (!isset($this->data['pm_id']) && $preserv['old_pm_id']) $content['pm_id'] = $preserv['old_pm_id'];
 209  
 210          if ($content['pm_id'])
 211          {
 212              $preserv['ts_project_blur'] = $content['ts_project_blur'] = $this->link->title('projectmanager',$content['pm_id']);
 213          }
 214          $content['ts_title_blur'] = $preserv['ts_title_blur'] = $preserv['ts_title_blur'] ? $preserv['ts_title_blur'] : $preserv['ts_project_blur'];
 215  
 216          $readonlys = array(
 217              'button[delete]'   => !$this->data['ts_id'] || !$this->check_acl(EGW_ACL_DELETE),
 218              'button[edit]'     => !$view || !$this->check_acl(EGW_ACL_EDIT),
 219              'button[save]'     => $view,
 220              'button[save_new]' => $view,
 221              'button[apply]'    => $view,
 222          );
 223          if ($view)
 224          {
 225              foreach(array_merge(array_keys($this->data),array('pm_id','pl_id','link_to')) as $key)
 226              {
 227                  $readonlys[$key] = true;
 228              }
 229          }
 230          $edit_grants = $this->grant_list(EGW_ACL_EDIT);
 231          if (count($edit_grants) == 1)
 232          {
 233              $readonlys['ts_owner'] = true;
 234          }
 235          $GLOBALS['egw_info']['flags']['app_header'] = lang('timesheet').' - '.
 236              ($view ? lang('View') : ($this->data['ts_id'] ? lang('Edit') : lang('Add')));
 237          
 238          $etpl =& new etemplate('timesheet.edit');
 239          // supress unknow widget 'projectmanager-*', if projectmanager is not installed or old
 240          if (!@file_exists(EGW_INCLUDE_ROOT.'/projectmanager/inc/class.projectmanager_widget.inc.php'))
 241          {
 242              $etpl->set_cell_attribute('pm_id','disabled',true);
 243              $etpl->set_cell_attribute('pl_id','disabled',true);
 244          }        
 245          return $etpl->exec(TIMESHEET_APP.'.uitimesheet.edit',$content,array(
 246              'ts_owner' => $edit_grants,
 247          ),$readonlys,$preserv,2);
 248      }
 249  
 250      /**
 251       * query projects for nextmatch in the projects-list
 252       *
 253       * reimplemented from so_sql to disable action-buttons based on the acl and make some modification on the data
 254       *
 255       * @param array &$query
 256       * @param array &$rows returned rows/cups
 257       * @param array &$readonlys eg. to disable buttons based on acl
 258       */
 259  	function get_rows(&$query_in,&$rows,&$readonlys)
 260      {
 261          $this->show_sums = false;
 262          if ($query_in['filter'])
 263          {
 264              $date_filter = $this->date_filter($query_in['filter'],$query_in['startdate'],$query_in['enddate']);
 265              
 266              $start = explode('-',date('Y-m-d',$query_in['startdate']+12*60*60));
 267              $end   = explode('-',date('Y-m-d',$query_in['enddate'] ? $query_in['enddate'] : $query_in['startdate']+7.5*24*60*60));
 268              
 269              // show year-sums, if we are year-aligned (show full years)?
 270              if ((int)$start[2] == 1 && (int)$start[1] == 1 && (int)$end[2] == 31 && (int)$end[1] == 12)
 271              {
 272                  $this->show_sums[] = 'year';
 273              }
 274              // show month-sums, if we are month-aligned (show full monthes)?
 275              if ((int)$start[2] == 1 && (int)$end[2] == (int)date('d',mktime(12,0,0,$end[1]+1,0,$end[0])))
 276              {
 277                  $this->show_sums[] = 'month';
 278              }
 279              // show week-sums, if we are week-aligned (show full weeks)?
 280              $week_start_day = $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'];
 281              if (!$week_start_day) $week_start_day = 'Sunday';
 282              switch($week_start_day)
 283              {
 284                  case 'Sunday': $week_end_day = 'Saturday'; break;
 285                  case 'Monday': $week_end_day = 'Sunday'; break;
 286                  case 'Saturday': $week_end_day = 'Friday'; break;
 287              }
 288              $filter_start_day = date('l',$query_in['startdate']+12*60*60);
 289              $filter_end_day   = $query_in['enddate'] ? date('l',$query_in['enddate']+12*60*60) : false;
 290              //echo "<p align=right>prefs: $week_start_day - $week_end_day, filter: $filter_start_day - $filter_end_day</p>\n";
 291              if ($filter_start_day == $week_start_day && (!$filter_end_day || $filter_end_day == $week_end_day))
 292              {
 293                  $this->show_sums[] = 'week';
 294              }
 295              // show day-sums, if range <= 5 weeks
 296              if (!$query_in['enddate'] || $query_in['enddate'] - $query_in['startdate'] < 36*24*60*60)
 297              {
 298                  $this->show_sums[] = 'day';
 299              }
 300          }
 301          //echo "<p align=right>show_sums=".print_r($this->show_sums,true)."</p>\n";
 302          $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP,$query_in);
 303          $query = $query_in;    // keep the original query
 304          
 305          if ((int)$query['filter2'] != (int)$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['show_details'])
 306          {
 307              $GLOBALS['egw']->preferences->add(TIMESHEET_APP,'show_details',(int)$query['filter2']);
 308              $GLOBALS['egw']->preferences->save_repository(true);
 309          }
 310          unset($query['col_filter']['cat_id']);
 311          if ($query['cat_id'])
 312          {
 313              if (!is_object($GLOBALS['egw']->categories))
 314              {
 315                  $GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories');
 316              }
 317              $cats = $GLOBALS['egw']->categories->return_all_children((int)$query['cat_id']);
 318              $query['col_filter']['cat_id'] = count($cats) > 1 ? $cats : $query['cat_id'];
 319          }
 320          $GLOBALS['egw_info']['flags']['app_header'] = lang('timesheet');
 321          if ($query['col_filter']['ts_owner'])
 322          {
 323              $GLOBALS['egw_info']['flags']['app_header'] .= ': '.$GLOBALS['egw']->common->grab_owner_name($query['col_filter']['ts_owner']);
 324          }
 325          else
 326          {
 327              unset($query['col_filter']['ts_owner']);
 328          }
 329          if ($query['filter'])
 330          {
 331              $query['col_filter'][0] = $date_filter;
 332              
 333              // generate a meaningful app-header / report title
 334              if ($this->show_sums['month'])
 335              {
 336                  if ((int)$start[1] == 1 && (int) $end[1] == 12)        // whole year(s)
 337                  {
 338                      $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $start[0] . ($start[0] != $end[0] ? ' - '.$end[0] : '');
 339                  }
 340                  else
 341                  {
 342                      $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang(date('F',$query['startdate']+12*60*60)) . ' ' . $start[0];
 343                      if ($start[0] != $end[0] || $start[1] != $end[1])
 344                      {
 345                          $GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . lang(date('F',$query['enddate']+12*60*60)) . ' ' . $end[0];
 346                      }
 347                  }
 348              }
 349              elseif ($this->show_sums['week'])
 350              {
 351                  $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang('week') . ' ' . date('W',$query['startdate']+36*60*60) . '/' . $start[0];
 352                  if ($query['enddate'] && $query['enddate'] - $query['startdate'] > 10*24*60*60)
 353                  {
 354                      $GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . date('W',$query['enddate']-36*60*60) . '/' . $end[0];
 355                  }
 356              }
 357              else
 358              {
 359                  $df = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
 360                  $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $GLOBALS['egw']->common->show_date($query['startdate']+12*60*60,$df,false);
 361                  if ($start != $end)
 362                  {
 363                      $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.$GLOBALS['egw']->common->show_date($query['enddate']+12*60*60,$df,false);
 364                  }
 365              }
 366              if ($query['filter'] == 'custom')    // show the custome dates
 367              {
 368                  if (!is_object($GLOBALS['egw']->js))
 369                  {
 370                      $GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript');
 371                  }
 372                  $GLOBALS['egw']->js->set_onload("set_style_by_class('*','custom_hide','visibility','visible');");
 373              }
 374          }
 375          $total = parent::get_rows($query,$rows,$readonlys);
 376          
 377          unset($query['col_filter'][0]);
 378          
 379          $readonlys = array();
 380          foreach($rows as $n => $val)
 381          {
 382              $row =& $rows[$n];
 383              
 384              $row['class'] = 'row';
 385              if ($row['ts_id'] <= 0)    // sums
 386              {
 387                  $readonlys["view[$row[ts_id]]"] = $readonlys["edit[$row[ts_id]]"] = $readonlys["delete[$row[ts_id]]"] = true;
 388                  if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200;    // fix for DSL change
 389                  switch($row['ts_id'])
 390                  {
 391                      case 0:    // day-sum
 392                          $row['ts_title'] = lang('Sum %1:',lang(date('l',$row['ts_start'])).' '.$GLOBALS['egw']->common->show_date($row['ts_start'],
 393                              $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],false));
 394                          break;
 395                      case -1:    // week-sum
 396                          $row['ts_title'] = lang('Sum %1:',lang('week').' '.substr($row['ts_week'],4).'/'.substr($row['ts_week'],0,4));
 397                          break;
 398                      case -2:    // month-sum
 399                          $row['ts_title'] = lang('Sum %1:',lang(date('F',$row['ts_start'])).' '.substr($row['ts_month'],0,4));
 400                          break;
 401                      case -3:    // year-sum
 402                          $row['ts_title'] = lang('Sum %1:',$row['ts_year']);
 403                          break;
 404                  }    
 405                  $row['ts_start'] = $row['ts_quantity'] = $row['ts_unitprice'] = '';
 406                  $row['class'] = 'th';
 407                  $row['titleClass'] = 'titleSum';
 408                  continue;
 409              }
 410              if (!$this->check_acl(EGW_ACL_EDIT,$row))
 411              {
 412                  $readonlys["edit[$row[ts_id]]"] = true;
 413              }
 414              if (!$this->check_acl(EGW_ACL_DELETE,$row))
 415              {
 416                  $readonlys["delete[$row[ts_id]]"] = true;
 417              }
 418              if ($query['col_filter']['ts_project'] || !$query['filter2'])
 419              {
 420                  unset($row['ts_project']);    // dont need or want to show it
 421              }
 422              else
 423              {
 424                  if (($links = $this->link->get_links(TIMESHEET_APP,$row['ts_id'],'projectmanager')))
 425                  {
 426                      $row['ts_link'] = array(
 427                          'app' => 'projectmanager',
 428                          'id'  => array_shift($links),
 429                      );
 430                  }
 431                  $row['ts_link']['title'] = $row['ts_project'];
 432              }
 433              if (!$query['filter2'])
 434              {
 435                  unset($row['ts_description']);
 436              }
 437              else
 438              {
 439                  $row['titleClass'] = 'titleDetails';
 440              }
 441          }
 442          if ($query['col_filter']['ts_owner']) $rows['ownerClass'] = 'noPrint';
 443          $rows['no_owner_col'] = $query['no_owner_col'];
 444          if ($query['filter'])
 445          {
 446              $rows['duration'] = $this->summary['duration'];
 447              $rows['price'] = $this->summary['price'];
 448          }
 449          return $total;        
 450      }
 451  
 452      /**
 453       * List timesheet entries
 454       *
 455       * @param array $content=null
 456       */
 457  	function index($content = null,$msg='')
 458      {
 459          $etpl =& new etemplate('timesheet.index');
 460          
 461          if ($_GET['msg']) $msg = $_GET['msg'];
 462          
 463          if ($content['nm']['rows']['delete'])
 464          {
 465              list($ts_id) = each($content['nm']['rows']['delete']);
 466              if ($this->delete($ts_id))
 467              {
 468                  $msg = lang('Entry deleted');
 469              }
 470              else
 471              {
 472                  $msg = lang('Error deleting the entry!!!');
 473              }
 474          }
 475          $content = array(
 476              'nm' => $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP),
 477              'msg' => $msg,
 478          );        
 479          if (!is_array($content['nm']))
 480          {
 481              $date_filters = array('All');
 482              foreach($this->date_filters as $name => $date)
 483              {
 484                  $date_filters[$name] = $name;
 485              }
 486              $date_filters['custom'] = 'custom';
 487  
 488              $content['nm'] = array(
 489                  'get_rows'       =>    TIMESHEET_APP.'.uitimesheet.get_rows',
 490                  'options-filter' => $date_filters,
 491                  'options-filter2' => array('No details','Details'),
 492                  'order'          =>    'ts_start',// IO name of the column to sort after (optional for the sortheaders)
 493                  'sort'           =>    'DESC',// IO direction of the sort: 'ASC' or 'DESC'
 494                  'header_right'   => 'timesheet.index.dates',
 495                  'filter_onchange' => "set_style_by_class('*','custom_hide','visibility',this.value == 'custom' ? 'visible' : 'hidden'); if (this.value != 'custom') this.form.submit();",
 496                  'filter2'        => (int)$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['show_details'],
 497              );
 498          }
 499          $read_grants = $this->grant_list(EGW_ACL_READ);
 500          $content['nm']['no_owner_col'] = count($read_grants) == 1;
 501  
 502          return $etpl->exec(TIMESHEET_APP.'.uitimesheet.index',$content,array(
 503              'ts_project' => $this->query_list('ts_project'),
 504              'ts_owner'   => $read_grants,
 505          ),$readonlys,$preserv);
 506      }
 507  }


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