[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/addressbook/inc/ -> class.uicontacts.inc.php (source)

   1  <?php
   2  /**************************************************************************\
   3  * eGroupWare - Adressbook - General user interface object                  *
   4  * http://www.egroupware.org                                                *
   5  * Written and (c) 2005 by Cornelius_weiss <egw@von-und-zu-weiss.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.uicontacts.inc.php 20923 2006-04-05 13:44:56Z nelius_weiss $ */
  14  
  15  require_once (EGW_INCLUDE_ROOT.'/addressbook/inc/class.bocontacts.inc.php');
  16  
  17  /**
  18   * General user interface object of the adressbook
  19   *
  20   * @package addressbook
  21   * @author Cornelius Weiss <egw@von-und-zu-weiss.de>
  22   * @copyright (c) 2005 by Cornelius Weiss <egw@von-und-zu-weiss.de>
  23   * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
  24   */
  25  class uicontacts extends bocontacts
  26  {
  27      var $public_functions = array(
  28          'search'    => True,
  29          'edit'        => True,
  30          'view'        => True,
  31      );
  32  
  33  	function uicontacts($contact_app='addressbook')
  34      {
  35          $this->bocontacts($contact_app);
  36          foreach(array(
  37              'tmpl'    => 'etemplate.etemplate',
  38          ) as $my => $app_class)
  39          {
  40              list(,$class) = explode('.',$app_class);
  41  
  42              if (!is_object($GLOBALS['egw']->$class))
  43              {
  44                  $GLOBALS['egw']->$class =& CreateObject($app_class);
  45              }
  46              $this->$my = &$GLOBALS['egw']->$class;
  47          }
  48          // our javascript
  49          // to be moved in a seperate file if rewrite is over
  50          $GLOBALS['egw_info']['flags']['java_script'] .= $this->js();
  51  
  52      }
  53      
  54      /**
  55      * Edit a contact 
  56      *
  57      * @param array $content=null submitted content
  58      * @param int $_GET['contact_id'] contact_id manly for popup use
  59      * @param bool $_GET['makecp'] ture if you want do copy the contact given by $_GET['contact_id']
  60      */
  61  	function edit($content=null)
  62      {
  63          if (!is_object($this->link))
  64          {
  65              if (!is_object($GLOBALS['egw']->link))
  66              {
  67                  $GLOBALS['egw']->link =& CreateObject('phpgwapi.bolink');
  68              }
  69              $this->link =& $GLOBALS['egw']->link;
  70          }
  71          if (is_array($content))
  72          {
  73              list($button) = each($content['button']);
  74              switch($button)
  75              {
  76                  case 'save':
  77                  case 'apply':
  78                      $links = false;
  79                      if (!$content['id'] && is_array($content['link_to']['to_id']))
  80                      {
  81                          $links = $content['link_to']['to_id'];
  82                      }
  83                      $content = $this->save($content);
  84                      // writing links for new entry, existing ones are handled by the widget itself
  85                      if ($links && $content['id'])    
  86                      {
  87                          $this->link->link('addressbook',$content['id'],$links);
  88                      }
  89                      if ($button == 'save')
  90                      {
  91                          echo "<html><body><script>var referer = opener.location;opener.location.href = referer;window.close();</script></body></html>\n";
  92                          $GLOBALS['egw']->common->egw_exit();
  93                      }
  94                      $content['link_to']['to_id'] = $content['id'];
  95                      $GLOBALS['egw_info']['flags']['java_script'] .= "<script LANGUAGE=\"JavaScript\">
  96                          var referer = opener.location;
  97                          opener.location.href = referer;</script>";
  98                      break;
  99                      
 100                  case 'delete':
 101                      if(!$this->delete($content));
 102                      {
 103                          echo "<html><body><script>var referer = opener.location;opener.location.href = referer;window.close();</script></body></html>\n";
 104                          $GLOBALS['egw']->common->egw_exit();
 105                      }
 106                      break;
 107              }
 108          }
 109          else
 110          {
 111              $content = array();
 112              $contact_id = $_GET['contact_id'] ? $_GET['contact_id'] : 0;
 113              $view = $_GET['view'];
 114              
 115              if ($contact_id)
 116              {
 117                  $content = $this->read($contact_id);
 118              }
 119              else // look if we have presets for a new contact
 120              {
 121                  foreach($this->get_contact_conlumns() as $field => $data)
 122                  {
 123                      if ($_GET['presets'][$field]) $content[$field] = $_GET['presets'][$field];
 124                  }
 125              }
 126              
 127              if($content && $_GET['makecp'])    // copy the contact
 128              {
 129                  $content['link_to']['to_id'] = 0;
 130                  $this->link->link('addressbook',$content['link_to']['to_id'],'addressbook',$content['id'],
 131                      lang('Copied by %1, from record #%2.',$GLOBALS['egw']->common->display_fullname('',
 132                      $GLOBALS['egw_info']['user']['account_firstname'],$GLOBALS['egw_info']['user']['account_lastname']),
 133                      $content['id']));
 134                  unset($content['id']);
 135              }
 136              else
 137              {
 138                  $content['link_to']['to_id'] = (int) $contact_id;
 139              }
 140          }
 141  
 142          //_debug_array($content);
 143          $readonlys['button[delete]'] = !$this->check_perms(EGW_ACL_DELETE,$content);
 144          $readonlys['button[copy]'] = $readonlys['button[edit]'] = $readonlys['button[vcard]'] = true;
 145  
 146          $preserv = array(
 147              'id' => $content['id'],
 148              'lid' => $content['lid'],
 149              'tid' => $content['tid'],
 150              'owner' => $content['owner'],
 151              'fn' => $content['fn'],
 152              'geo' => $content['geo'],
 153              'access' => $content['access'],
 154          );
 155          
 156          for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i;
 157          $sel_options['tz'] = $tz;
 158          $content['tz'] = $content['tz'] ? $content['tz'] : 0;
 159          
 160          $content['link_to'] = array(
 161              'to_app' => 'addressbook',
 162              'to_id'  => $content['link_to']['to_id'],
 163          );
 164          
 165          $this->tmpl->read('addressbook.edit');
 166          return $this->tmpl->exec('addressbook.uicontacts.edit',$content,$sel_options,$readonlys,$preserv, 2);
 167      }
 168      
 169  	function view($content=null)
 170      {
 171          if(is_array($content))
 172          {
 173              list($button) = each($content['button']);
 174              switch ($button)
 175              {
 176                  case 'vcard':
 177                      $GLOBALS['egw']->redirect_link('/index.php','menuaction=addressbook.uivcard.out&ab_id=' .$content['id']);
 178  
 179                  case 'cancel':
 180                      $GLOBALS['egw']->redirect_link('/index.php','menuaction=addressbook.uiaddressbook.index');
 181  
 182                  case 'delete':
 183                      $GLOBALS['egw']->redirect_link('/index.php',array(
 184                          'menuaction' => 'addressbook.uiaddressbook.index',
 185                          'msg' => $this->delete($content) ? lang('Something went wrong by deleting this contact') : lang('Contact deleted !!!'),
 186                      ));
 187              }
 188          }
 189          else
 190          {
 191              if(!(int)$_GET['contact_id'] || !is_array($content = $this->read((int) $_GET['contact_id'])))
 192              {
 193                  $GLOBALS['egw']->redirect_link('/index.php',array(
 194                      'menuaction' => 'addressbook.uiaddressbook.index',
 195                      'msg' => $content,
 196                  ));
 197              }
 198          }
 199          foreach($content as $key => $val)
 200          {
 201              $readonlys[$key] = true;
 202              if (in_array($key,array('tel_home','tel_work','tel_cell')))
 203              {
 204                  $readonlys[$key.'2'] = true;
 205                  $content[$key.'2'] = $content[$key];
 206              }                
 207          }
 208          $content['view'] = true;
 209          $content['link_to'] = array(
 210              'to_app' => 'addressbook',
 211              'to_id'  => $content['id'],
 212          );
 213          $readonlys['link_to'] = $readonlys['customfields'] = true;
 214          $readonlys['button[save]'] = $readonlys['button[apply]'] = true;
 215          $readonlys['button[delete]'] = !$this->check_perms(EGW_ACL_DELETE,$content);
 216          $readonlys['button[edit]'] = !$this->check_perms(EGW_ACL_EDIT,$content);
 217          
 218          for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i;
 219          $sel_options['tz'] = $tz;
 220          $content['tz'] = $content['tz'] ? $content['tz'] : 0;
 221  
 222          $this->tmpl->read('addressbook.edit');
 223          foreach(array('email','email_home','url') as $name)
 224          {
 225              if ($content[$name] )
 226              {
 227                  $url = $name == 'url' ? $content[$name] : $this->email2link($content[$name]);
 228                  if (!is_array($url))
 229                  {
 230                      $this->tmpl->set_cell_attribute($name,'size','b,,1');
 231                  }
 232                  elseif ($url)
 233                  {
 234                      $content[$name.'_link'] = $url;
 235                      $this->tmpl->set_cell_attribute($name,'size','b,@'.$name.'_link,,,_blank');
 236                  }
 237                  $this->tmpl->set_cell_attribute($name,'type','label');
 238                  $this->tmpl->set_cell_attribute($name,'no_lang',true);
 239              }
 240          }
 241          $this->tmpl->exec('addressbook.uicontacts.view',$content,$sel_options,$readonlys,array('id' => $content['id']));
 242          
 243          $GLOBALS['egw']->hooks->process(array(
 244              'location' => 'addressbook_view',
 245              'ab_id'    => $content['id']
 246          ));
 247      }
 248      
 249      /**
 250       * convert email-address in compose link
 251       *
 252       * @param string $email email-addresse
 253       * @return array/string array with get-params or mailto:$email, or '' or no mail addresse
 254       */
 255  	function email2link($email)
 256      {
 257          if (!strstr($email,'@')) return '';
 258  
 259          if($GLOBALS['egw_info']['user']['apps']['felamimail'])
 260          {
 261              return array(
 262                  'menuaction' => 'felamimail.uicompose.compose',
 263                  'send_to'    => base64_encode($email)
 264              );
 265          }
 266          if($GLOBALS['egw_info']['user']['apps']['email'])
 267          {
 268              return array(
 269                  'menuaction' => 'email.uicompose.compose',
 270                  'to' => $email,
 271              );
 272          }
 273          return 'mailto:' . $email;
 274      }
 275  
 276  	function search($content='')
 277      {
 278          $GLOBALS['egw_info']['flags']['app_header'] = lang('Addressbook'). ' - '. lang('Advanced search');
 279          if(!($GLOBALS['egw_info']['server']['contact_repository'] == 'sql' || !isset($GLOBALS['egw_info']['server']['contact_repository'])))
 280          {
 281              $GLOBALS['egw']->common->phpgw_header();
 282              echo parse_navbar();
 283              echo '<p> Advanced Search is not supported for ldap storage yet. Sorry! </p>';
 284              $GLOBALS['egw']->common->egw_exit();
 285          }
 286          
 287          $content['advs']['msg'] = lang('Please select only one category');
 288          // This is no fun yet, as we dont have a sortorder in prefs now, AND as we are not able to sort within cf.
 289  //         $prefs = $GLOBALS['egw']->preferences->read_repository();
 290  //         foreach($prefs['addressbook'] as $key => $value)
 291  //         {
 292  //             if($value == 'addressbook_on') $content['advs']['colums_to_present'][$key] = lang($key);
 293  //         }
 294      
 295  //         echo 'addressbook.uicontacts.search->content:'; _debug_array($content);
 296          $content['advs']['hidebuttons'] = true;
 297          $content['advs']['input_template'] = 'addressbook.edit';
 298          $content['advs']['search_method'] = 'addressbook.bocontacts.search';
 299          $content['advs']['search_class_constructor'] = $contact_app;
 300          $content['advs']['colums_to_present'] = array(
 301              'id' => 'id',
 302              'n_given' => lang('first name'),
 303              'n_family' => lang('last name'),
 304              'email_home' => lang('home email'),
 305              'email' => lang('work email'),
 306              'tel_home' => lang('tel home'),
 307          );
 308          
 309          $content['advs']['row_actions'] = array(
 310              'view' => array(
 311                  'type' => 'button',
 312                  'options' => array(
 313                      'size' => 'view',
 314                      'onclick' => "location.href='".$GLOBALS['egw']->link('/index.php',
 315                      array('menuaction' => 'addressbook.uicontacts.view',)).'&contact_id=$row_cont[id]\';return false;',
 316              )),
 317              'edit' => array(
 318                  'type' => 'button',
 319                  'options' => array(
 320                      'size' => 'edit',
 321                      'onclick' => 'window.open(\''.
 322                      $GLOBALS['egw']->link('/index.php?menuaction=addressbook.uicontacts.edit').
 323                      '&contact_id=$row_cont[id] \',\'\',\'dependent=yes,width=850,height=440,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\');
 324                      return false;',
 325                  )),
 326              'delete' => array(
 327                  'type' => 'button',
 328                  'method' => 'addressbook.bocontacts.delete',
 329                  'options' => array(
 330                      'size' => 'delete',
 331                      'onclick' => 'if(!confirm(\''. lang('Do your really want to delete this contact?'). '\')) return false;',
 332                  )),
 333          );
 334  /*        $content['advs']['actions']['email'] = array(
 335                  'type' => 'button',
 336                  'options' => array(
 337                      'label' => lang('email'),
 338                      'no_lang' => true,
 339          ));
 340          $content['advs']['actions']['export'] = array(
 341                  'type' => 'button',
 342                  'options' => array(
 343                      'label' => lang('export'),
 344                      'no_lang' => true,
 345          ));*/
 346          $content['advs']['actions']['delete'] = array(
 347                  'type' => 'button',
 348                  'method' => 'addressbook.bocontacts.delete',
 349                  'options' => array(
 350                      'label'  => lang('delete'),
 351                      'no_lang' => true,
 352                      'onclick' => 'if(!confirm(\''. lang('WARNING: All contacts found will be deleted!'). '\')) return false;',
 353          ));
 354          
 355          for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i;
 356          $sel_options['tz'] = $tz + array('' => lang('doesn\'t matter'));
 357          
 358          $this->tmpl->read('addressbook.search');
 359          return $this->tmpl->exec('addressbook.uicontacts.search',$content,$sel_options,$readonlys,$preserv);
 360      }
 361      
 362      function js()
 363      {
 364          return '<script LANGUAGE="JavaScript">
 365          
 366  		function showphones(form) 
 367          {
 368              set_style_by_class("table","editphones","display","inline");
 369              if (form) {
 370                  copyvalues(form,"tel_home","tel_home2");
 371                  copyvalues(form,"tel_work","tel_work2");
 372                  copyvalues(form,"tel_cell","tel_cell2");
 373              }
 374          }
 375          
 376  		function hidephones(form) 
 377          {
 378              set_style_by_class("table","editphones","display","none");
 379              if (form) {
 380                  copyvalues(form,"tel_home2","tel_home");
 381                  copyvalues(form,"tel_work2","tel_work");
 382                  copyvalues(form,"tel_cell2","tel_cell");
 383              }
 384          }
 385          
 386  		function copyvalues(form,src,dst){
 387              var srcelement = getElement(form,src);  //ById("exec["+src+"]");
 388              var dstelement = getElement(form,dst);  //ById("exec["+dst+"]");
 389              if (srcelement && dstelement) {
 390                  dstelement.value = srcelement.value;
 391              }
 392          }
 393          
 394  		function getElement(form,pattern){
 395              for (i = 0; i < form.length; i++){
 396                  if(form.elements[i].name){
 397                      var found = form.elements[i].name.search(pattern);
 398                      if (found != -1){
 399                          return form.elements[i];
 400                      }
 401                  }
 402              }
 403          }
 404          
 405          </script>';
 406      }
 407  }


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