[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/bookmarks/inc/ -> class.ui.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - Bookmarks                                                   *
   4      * http://www.egroupware.org                                                *
   5      * Based on Bookmarker Copyright (C) 1998  Padraic Renaghan                 *
   6      *                     http://www.renaghan.com/bookmarker                   *
   7      * Ported to phpgroupware by Joseph Engo                                    *
   8      * Ported to three-layered design by Michael Totschnig                      *
   9      * --------------------------------------------                             *
  10      *  This program is free software; you can redistribute it and/or modify it *
  11      *  under the terms of the GNU General Public License as published by the   *
  12      *  Free Software Foundation; either version 2 of the License, or (at your  *
  13      *  option) any later version.                                              *
  14      \**************************************************************************/
  15  
  16      /* $Id: class.ui.inc.php 21319 2006-04-10 08:32:14Z omgs $ */
  17  
  18      define('TREE',1);
  19      define('_LIST',2);
  20      define('CREATE',3);
  21      define('SEARCH',4);
  22  
  23      class ui
  24      {
  25          var $t;
  26          var $bo;
  27          var $img;
  28          var $expandedcats;
  29          var $nextmatchs;
  30  
  31          var $public_functions = array
  32          (
  33              'edit' => True,
  34              'create' => True,
  35              '_list' => True,
  36              'search' => True,
  37              'tree' => True,
  38              'view' => True,
  39              'mail' => True,
  40              'mass' => True,
  41              'redirect' => True,
  42              'export' => True,
  43              'import' => True
  44          );
  45  
  46          function ui()
  47          {
  48              $this->t = $GLOBALS['egw']->template;
  49              $this->bo =& CreateObject('bookmarks.bo');
  50              $this->img = array(
  51                  'collapse' => $GLOBALS['egw']->common->image('bookmarks','tree_collapse'),
  52                  'expand' => $GLOBALS['egw']->common->image('bookmarks','tree_expand'),
  53                  'edit' => $GLOBALS['egw']->common->image('bookmarks','edit'),
  54                  'view' => $GLOBALS['egw']->common->image('bookmarks','document'),
  55                  'mail' => $GLOBALS['egw']->common->image('bookmarks','mail'),
  56                  'delete' => $GLOBALS['egw']->common->image('bookmarks','delete')
  57              );
  58              $this->expandedcats = array();
  59              $this->location_info = $this->bo->read_session_data();
  60              $this->nextmatchs =& CreateObject('phpgwapi.nextmatchs');
  61  
  62          }
  63  
  64  		function init()
  65          {
  66              // we maintain two levels of state:
  67              // returnto the main interface (tree, list, or search)
  68              // returnto2 temporaray interface (create, edit, view, mail)
  69              $returnto2 = $this->location_info['returnto2'];
  70              $returnto = $this->location_info['returnto'];
  71              if ($returnto2)
  72              {
  73                  $this->$returnto2();
  74              }
  75              elseif ($returnto)
  76              {
  77                  $this->$returnto();
  78              }
  79              elseif ($GLOBALS['egw_info']['user']['preferences']['bookmarks']['defaultview'] == 'tree')
  80              {
  81                  $this->tree();
  82              }
  83              else
  84              {
  85                  $this->_list();
  86              }
  87          }
  88  
  89  		function app_header($where=0)
  90          {
  91              $tabs[1]['label'] = lang('Tree view');
  92              $tabs[1]['link']  = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.tree');
  93  
  94              $tabs[2]['label'] = lang('List');
  95              $tabs[2]['link']  = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui._list');
  96  
  97              if (! $GLOBALS['egw']->acl->check('anonymous',1,'bookmarks'))
  98              {
  99                  $tabs[3]['label'] = lang('New');
 100                  $tabs[3]['link']  = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.create');
 101              }
 102  
 103              $tabs[4]['label'] = lang('Search');
 104              $tabs[4]['link']  = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.search');
 105  
 106              $this->t->set_var('app_navbar',$GLOBALS['egw']->common->create_tabs($tabs,$where));
 107          }
 108  
 109  		function app_messages()
 110          {
 111              if ($this->bo->error_msg)
 112              {
 113                  $bk_output_html = lang('Error') . ': ' . $this->bo->error_msg ;
 114              }
 115              if ($this->bo->msg)
 116              {
 117                  $bk_output_html .= $this->bo->msg;
 118              }
 119  
 120              if ($bk_output_html)
 121              {
 122                  $this->t->set_var('messages',$bk_output_html);
 123              }
 124          }
 125  
 126  		function app_template()
 127          {
 128              $this->t->set_var(array(
 129                  'lang_url' => lang('URL'),
 130                  'lang_name' => lang('Name'),
 131                  'lang_desc' => lang('Description'),
 132                  'lang_keywords' => lang('Keywords'),
 133                  'lang_access' => lang('Private'),
 134                  'lang_category' => lang('Category'),
 135                  'lang_rating' => lang('Rating'),
 136                  'lang_owner' => lang('Created by'),
 137                  'lang_added' => lang('Date added'),
 138                  'lang_updated' => lang('Date last updated'),
 139                  'lang_visited' => lang('Date last visited'),
 140                  'lang_visits' => lang('Total visits'),
 141                  'cancel_button' => ('<input type="image" name="cancel" title="' . lang('Done') . '" src="'
 142                      . $GLOBALS['egw']->common->image('bookmarks','cancel') . '" border="0">'
 143                  ),
 144                  'save_button' => ('<input type="image" name="save" title="' . lang('Save') . '" src="'
 145                      . $GLOBALS['egw']->common->image('bookmarks','save') . '" border="0">'
 146                  ),
 147                  'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
 148                  'category_image' => ('<input type="image" name="edit_category" title="' . lang('Edit category') . '" src="'
 149                      . $GLOBALS['egw']->common->image('bookmarks','edit') . '" border="0">'
 150                  ),
 151              ));
 152          }
 153  
 154  		function create()
 155          {
 156              //if we redirect to edit categories, we remember form values and try to come back to create
 157              if ($_POST['edit_category_x'] || $_POST['edit_category_y'])
 158              {
 159                  $this->bo->grab_form_values($this->location_info['returnto'],'create',$_POST['bookmark']);
 160                  $GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=bookmarks&cats_level=True&global_cats=True'));
 161              }
 162              //save bookmark
 163              if ($_POST['save_x'] || $_POST['save_y'])
 164              {
 165                  $bookmark = $_POST['bookmark'];
 166                  $bm_id = $this->bo->add($bookmark);
 167                  if ($bm_id)
 168                  {
 169                      $this->location_info['bm_id'] = $bm_id;
 170                      $this->view();
 171                      return;
 172                  }
 173              }
 174              //if we come back from editing categories we restore form values
 175              elseif ($this->location_info['returnto2'] == 'create')
 176              {
 177                  $bookmark['name']        = $this->location_info['bookmark']['name'];
 178                  $bookmark['url']         = $this->location_info['bookmark']['url'];
 179                  $bookmark['desc']        = $this->location_info['bookmark']['desc'];
 180                  $bookmark['keywords']    = $this->location_info['bookmark']['keywords'];
 181                  $bookmark['category']    = $this->location_info['bookmark']['category'];
 182                  $bookmark['rating']      = $this->location_info['bookmark']['rating'];
 183                  $bookmark['access']      = $this->location_info['bookmark']['access'];
 184              }
 185              //if the user cancelled we go back to the view we came from
 186              if ($_POST['cancel_x'] || $_POST['cancel_y'])
 187              {
 188                  unset($this->location_info['returnto2']);
 189                  $this->init();
 190                  return;
 191              }
 192              //store the view, we came from originally(list,tree,search), and the view we are in
 193              $this->location_info['bookmark'] = False;
 194              $this->location_info['returnto2'] = 'create';
 195              $this->bo->save_session_data($this->location_info);
 196  
 197              $GLOBALS['egw']->common->egw_header();
 198              echo parse_navbar();
 199              $this->app_header(CREATE);
 200  
 201              $this->t->set_file(array(
 202                  'common_'            => 'common.tpl',
 203                  'form'               => 'form.tpl'
 204              ));
 205              $this->t->set_block('form','body');
 206              $this->t->set_block('form','form_info');
 207  
 208              $selected[$bookmark['rating']] = ' selected';
 209              $this->app_template();
 210  
 211              $this->t->set_var(array(
 212                  'form_info' => '',
 213                  'lang_header' => lang('new bookmark'),
 214                  'input_category' => $this->bo->categories_list($bookmark['category']),
 215                  'input_rating' => ('<select name="bookmark[rating]">'
 216                      . ' <option value="0"' . $selected[0] . '>--</option>'
 217                      . ' <option value="1"' . $selected[1] . '>1 - ' . lang('Lowest') . '</option>'
 218                      . ' <option value="2"' . $selected[2] . '>2</option>'
 219                      . ' <option value="3"' . $selected[3] . '>3</option>'
 220                      . ' <option value="4"' . $selected[4] . '>4</option>'
 221                      . ' <option value="5"' . $selected[5] . '>5</option>'
 222                      . ' <option value="6"' . $selected[6] . '>6</option>'
 223                      . ' <option value="7"' . $selected[7] . '>7</option>'
 224                      . ' <option value="8"' . $selected[8] . '>8</option>'
 225                      . ' <option value="9"' . $selected[9] . '>9</option>'
 226                      . ' <option value="10"' . $selected[10] . '>10 - ' . lang('Highest') . '</option>'
 227                      . '</select>'
 228                  ),
 229                  'input_url' => ('<input name="bookmark[url]" size="60" maxlength="255" value="' .
 230                      ($bookmark['url']?$bookmark['url']:'http://') . '">'
 231                  ),
 232                  'input_name' => ('<input name="bookmark[name]" size="60" maxlength="255" value="' .
 233                      $bookmark['name'] . '">'
 234                  ),
 235                  'input_desc' => ('<textarea name="bookmark[desc]" rows="3" cols="60" wrap="virtual">' .
 236                      $bookmark['desc'] . '</textarea>'
 237                  ),
 238                  'input_keywords' => ('<input type="text" name="bookmark[keywords]" size="60" maxlength="255" value="' .
 239                      $bookmark['keywords'] . '">'
 240                  ),
 241                  'input_access' => ('<input type="checkbox" name="bookmark[access]" value="private"' .
 242                      ($bookmark['access'] ?' checked' : '') . '>'
 243                  ),
 244              ));
 245              $this->t->fp('body','form');
 246              $this->app_messages();
 247              $this->t->pfp('out','common_');
 248          }
 249  
 250  		function edit()
 251          {
 252              if (isset($_GET['bm_id']))
 253              {
 254                  $bm_id = $_GET['bm_id'];
 255              }
 256              elseif (is_array($this->location_info))
 257              {
 258                  $bm_id = $this->location_info['bm_id'];
 259              }
 260              //if the user cancelled we go back to the view we came from
 261              if ($_POST['cancel_x'] || $_POST['cancel_y'] || !isset($bm_id))
 262              {
 263                  unset($this->location_info['returnto2']);
 264                  $this->init();
 265                  return;
 266              }
 267              //delete bookmark and go back to view we came from
 268              if ($_POST['delete_x'] || $_POST['delete_y'])
 269              {
 270                  $this->bo->delete($bm_id);
 271                  unset($this->location_info['returnto2']);
 272                  $this->init();
 273                  return;
 274              }
 275              //if we redirect to edit categories, we remember form values and try to come back to edit
 276              if ($_POST['edit_category_x'] || $_POST['edit_category_y'])
 277              {
 278                  $this->bo->grab_form_values($this->location_info['returnto'],'edit',$_POST['bookmark']);
 279                  $GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=bookmarks&cats_level=True&global_cats=True'));
 280              }
 281              //save bookmark and go to view interface
 282              if ($_POST['save_x'] || $_POST['save_y'])
 283              {
 284                  $bookmark = $_POST['bookmark'];
 285                  if ($this->bo->update($bm_id,$bookmark))
 286                  {
 287                      $this->location_info['bm_id'] = $bm_id;
 288                      $this->view();
 289                      return;
 290                  }
 291              }
 292              $bookmark = $this->bo->read($bm_id);
 293  
 294              if (!$bookmark[EGW_ACL_EDIT])
 295              {
 296                  $this->bo->error_msg = lang('Bookmark not editable');
 297                  unset($this->location_info['returnto2']);
 298                  $this->init();
 299                  return;
 300              }
 301  
 302              //if we come back from editing categories we restore form values
 303              if ($this->location_info['bookmark'])
 304              {
 305                  $bookmark['name']     = $location_info['bookmark_name'];
 306                  $bookmark['url']      = $location_info['bookmark_url'];
 307                  $bookmark['desc']     = $location_info['bookmark_desc'];
 308                  $bookmark['keywords'] = $location_info['bookmark_keywords'];
 309                  $bookmark['category'] = $location_info['bookmark_category'];
 310                  $bookmark['rating']   = $location_info['bookmark_rating'];
 311              }
 312  
 313              //store the view we are in
 314              $this->location_info['bookmark'] = False;
 315              $this->location_info['returnto2'] = 'edit';
 316              $this->location_info['bm_id'] = $bm_id;
 317              $this->bo->save_session_data($this->location_info);
 318  
 319              $GLOBALS['egw']->common->egw_header();
 320              echo parse_navbar();
 321              $this->app_header();
 322  
 323              $this->t->set_file(array(
 324                  'common_'            => 'common.tpl',
 325                  'form'               => 'form.tpl'
 326              ));
 327              $this->t->set_block('form','body');
 328              $this->t->set_block('form','form_info');
 329  
 330              $this->bo->date_information($this->t,$bookmark['info']);
 331  
 332              $rs[$bookmark['rating']] = ' selected';
 333              $rating_select = '<select name="bookmark[rating]">'
 334                  . ' <option value="0">--</option>'
 335                  . ' <option value="1"' . $rs[1] . '>1 - ' . lang('Lowest') . '</option>'
 336                  . ' <option value="2"' . $rs[2] . '>2</option>'
 337                  . ' <option value="3"' . $rs[3] . '>3</option>'
 338                  . ' <option value="4"' . $rs[4] . '>4</option>'
 339                  . ' <option value="5"' . $rs[5] . '>5</option>'
 340                  . ' <option value="6"' . $rs[6] . '>6</option>'
 341                  . ' <option value="7"' . $rs[7] . '>7</option>'
 342                  . ' <option value="8"' . $rs[8] . '>8</option>'
 343                  . ' <option value="9"' . $rs[9] . '>9</option>'
 344                  . ' <option value="10"' . $rs[10] . '>10 - ' . lang('Highest') . '</option>'
 345                  . '</select>';
 346  
 347              $account =& CreateObject('phpgwapi.accounts',$bookmark['owner']);
 348              $ad      = $account->read_repository();
 349  
 350              $this->app_template();
 351              $this->t->set_var(array(
 352                  'lang_header' => lang('Edit bookmark'),
 353                  'total_visits' => $bookmark['visits'],
 354                  'owner_value' => $GLOBALS['egw']->common->display_fullname($ad['account_lid'],$ad['firstname'],$ad['lastname'])
 355              ));
 356              $this->t->parse('info','form_info');
 357              $this->t->set_var(array(
 358                  'form_info' => '',
 359                  'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.edit&bm_id=' . $bm_id),
 360                  'lang_access' => lang('Private'),
 361                  'input_access' => ('<input type="checkbox" name="bookmark[access]" value="private"' .
 362                      ($bookmark['access']=='private'?' checked':'') . '>'
 363                  ),
 364                  'input_rating' => $rating_select,
 365                  'input_category' => $this->bo->categories_list($bookmark['category']),
 366                  'input_url' => ('<input name="bookmark[url]" size="60" maxlength="255" value="' .
 367                      $bookmark['url'] . '">'
 368                  ),
 369                  'input_name' => ('<input name="bookmark[name]" size="60" maxlength="255" value="' .
 370                      $bookmark['name'] . '">'
 371                  ),
 372                  'input_desc' => ('<textarea name="bookmark[desc]" rows="3" cols="60" wrap="virtual">' .
 373                      $bookmark['desc'] . '</textarea>'
 374                  ),
 375                  'input_keywords' => ('<input type="text" name="bookmark[keywords]" size="60" maxlength="255" value="' .
 376                      $bookmark['keywords'] . '">'
 377                  ),
 378                  'delete_button' => ($this->bo->check_perms($bm_id,EGW_ACL_DELETE,$bookmark['owner']) ?
 379                      ('<input type="image" name="delete" title="' . lang('Delete') . '" src="'
 380                          . $GLOBALS['egw']->common->image('bookmarks','delete') . '" border="0">'
 381                      ) :
 382                      ''
 383                  ),
 384              ));
 385  
 386              $this->t->fp('body','form');
 387              $this->app_messages();
 388              $this->t->pfp('out','common_');
 389          }
 390  
 391  		function _list()
 392          {
 393              if (is_array($this->location_info))
 394              {
 395                  $start = $this->location_info['start'];
 396                  $bm_cat = $this->location_info['bm_cat'];
 397              }
 398              if (isset($_GET['bm_cat']))
 399              {
 400                  $bm_cat = $_GET['bm_cat'];
 401              }
 402              if (isset($_GET['start']))
 403              {
 404                  $start = $_GET['start'];
 405              }
 406              if (isset($_POST['start']))
 407              {
 408                  $start = $_POST['start'];
 409              }
 410              $this->location_info['start'] = $start;
 411              $this->location_info['bm_cat'] = $bm_cat;
 412              $this->location_info['returnto'] = '_list';
 413              unset($this->location_info['returnto2']);
 414              $this->bo->save_session_data($this->location_info);
 415  
 416              $GLOBALS['egw']->common->egw_header();
 417              echo parse_navbar();
 418              $this->app_header(_LIST);
 419  
 420              $this->t->set_file(array(
 421                  'common_' => 'common.tpl',
 422                  'listbody'    => 'list.body.tpl'
 423              ));
 424  
 425              $this->t->set_var(array(
 426                  'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
 427                  'lang_url' => lang('URL'),
 428                  'lang_name' => lang('Name')
 429              ));
 430  
 431              // We need to send the $start var instead of the page number
 432              // Use appsession() to remeber the return page,instead of always passing it
 433              $this->print_list($where_clause,$start,$bm_cat,$bookmark_list);
 434  
 435              $this->t->set_var('BOOKMARK_LIST', $bookmark_list);
 436  
 437              $total_bookmarks = $this->bo->so->total_records;
 438              if ($total_bookmarks > $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])
 439              {
 440                  $next = $start + $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
 441                  $total_matchs = lang('showing %1 - %2 of %3',($start + 1),
 442                      ($next <= $total_bookmarks) ? $next : $total_bookmarks,$total_bookmarks);
 443              }
 444              else
 445              {
 446                  $total_matchs = lang('showing %1',$total_bookmarks);
 447              }
 448              if ($bm_cat)
 449              {
 450                  $total_matchs .= ' ' .
 451                      lang('from category %1',$GLOBALS['egw']->strip_html($this->bo->categories->id2name($bm_cat))) .
 452                      ' - <a href="' .
 453                      $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui._list&bm_cat=0&start=0') .
 454                      '">' .
 455                      lang('All bookmarks') .
 456                      '</a>';
 457              }
 458              $link_data = array
 459              (
 460                  'menuaction' => 'bookmarks.ui._list',
 461                  'bm_cat' => $bm_cat
 462              );
 463  
 464              $this->t->set_var(array(
 465                  'next_matchs_left' =>  $this->nextmatchs->left('/index.php',$start,$total_bookmarks,$link_data),
 466                  'next_matchs_right' => $this->nextmatchs->right('/index.php',$start,$total_bookmarks,$link_data),
 467                  'showing' => $total_matchs
 468              ));
 469  
 470              $this->t->fp('body','listbody');
 471              $this->app_messages();
 472              $this->t->pfp('out','common_');
 473          }
 474  
 475  		function search()
 476          {
 477              global $y, $x;
 478              if (is_array($this->location_info))
 479              {
 480                  $start = $this->location_info['searchstart'];
 481                  $x = $this->location_info['x'];
 482              }
 483              if (isset($_POST['x']))
 484              {
 485                  $x = $_POST['x'];
 486                  $this->location_info['x'] = $x;
 487              }
 488              if (isset($_POST['start']))
 489              {
 490                  $start = $_POST['start'];
 491                  $this->location_info['searchstart'] = $start;
 492              }
 493              $this->location_info['returnto'] = 'search';
 494  
 495              $this->bo->save_session_data($this->location_info);
 496  
 497              $GLOBALS['egw']->common->egw_header();
 498              echo parse_navbar();
 499              $this->app_header(SEARCH);
 500  
 501              $q =& CreateObject('bookmarks.sqlquery');
 502  
 503              $this->t->set_file(array(
 504                  'common_'  => 'common.tpl',
 505                  'searchbody'    => 'search.body.tpl',
 506                  'results' => 'search.results.tpl'
 507              ));
 508  
 509              // the following fields are selectable
 510              $field = array(
 511                  'bm_name'        => lang('Name'),
 512                  'bm_keywords'    => lang('Keywords'),
 513                  'bm_url'         => lang('URL'),
 514                  'bm_desc'        => lang('Description')
 515              //        'bm_category'    => 'Category',
 516              //        'bm_subcategory' => 'Sub Category',
 517              );
 518  
 519              // PHPLIB's sqlquery class loads this string when
 520              // no query has been specified.
 521              $noquery = "1=0";
 522  
 523              # build the where clause based on user entered fields
 524              if (isset($x))
 525              {
 526                  #
 527                  # we need to pre-process the input fields so we can
 528                  # handle quotes properly. we can't put an addslashes
 529                  # on the resulting sql because the sql_query object
 530                  # doesn't do the quotes correctly
 531                  foreach ($x as $key => $value)
 532                  {
 533                      if (substr($key,0,4) == 'sel_' && !preg_match('/^bm_(name|keywords|url|desc)$/',$value) ||
 534                          substr($key,0,5) == 'comp_' && !preg_match('/^(like|[<>=]{1,2})$/',$value))
 535                      {
 536                          continue;    // someone trying something nasty
 537                      }
 538                      $y[$key] = addslashes($value);
 539                  }
 540                  if (is_array($y)) $q->query = $q->where("y", 1);
 541              }
 542  
 543              $this->t->set_var(array(
 544                  'SEARCH_SELECT' => $search_select,
 545                  'FORM_ACTION'   => $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.search')
 546              ));
 547  
 548              # build the search form
 549              $this->t->set_var(QUERY_FORM, $q->form("x", $field, "qry", $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.search')));
 550  
 551              if ($q->query == $noquery)
 552              {
 553              }
 554              else
 555              {
 556                  $this->print_list($q->query, $start,0,$bookmark_list);
 557  
 558                  $total_bookmarks = $this->bo->so->total_records;
 559                  if ($total_bookmarks > $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])
 560                  {
 561                      $next = $start + $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
 562                      $total_matchs = lang('showing %1 - %2 of %3',($start + 1),
 563                      ($next <= $total_bookmarks) ? $next : $total_bookmarks,$total_bookmarks);
 564                  }
 565                  else
 566                  {
 567                      $total_matchs = lang('showing %1',$total_bookmarks);
 568                  }
 569                  $link_data = array
 570                  (
 571                      'menuaction' => 'bookmarks.ui.search'
 572                  );
 573  
 574                  $this->t->set_var(array(
 575                      'next_matchs_left' =>  $this->nextmatchs->left('/index.php',$start,$total_bookmarks,$link_data),
 576                      'next_matchs_right' => $this->nextmatchs->right('/index.php',$start,$total_bookmarks,$link_data),
 577                      'showing' => $total_matchs
 578                  ));
 579  
 580                  $this->t->set_var(array(
 581                      'QUERY_CONDITION' => $GLOBALS['egw']->strip_html($q->query),
 582                      'LANG_QUERY_CONDITION' => lang('Query Condition'),
 583                      'BOOKMARK_LIST'   => $bookmark_list
 584                  ));
 585                  $this->t->parse('QUERY_RESULTS', 'results');
 586              }
 587  
 588              $this->t->fp('body','searchbody');
 589              $this->app_messages();
 590              $this->t->pfp('out','common_');
 591          }
 592  
 593  		function print_list_break ($category_id)
 594          {
 595              $category = $GLOBALS['egw']->strip_html($this->bo->categories->id2name($category_id));
 596  
 597              $massupdate_shown = $GLOBALS['massupdate_shown'];
 598  
 599              // We only want to display the massupdate section once
 600              if (! $massupdate_shown)
 601              {
 602                  $this->t->set_var(array(
 603                      'lang_massupdate' => lang('Mass update:'),
 604                      'massupdate_delete_icon' => sprintf('<input type="image" name="delete" border="0" src="%s">',$this->img['delete']),
 605                      'massupdate_mail_icon' => sprintf('<input type="image" name="mail" border="0" src="%s">',$this->img['mail'])
 606                  ));
 607                  $massupdate_shown = True;
 608              }
 609              else
 610              {
 611                  $this->t->set_var(array(
 612                      'lang_massupdate' => '',
 613                      'massupdate_delete_icon' => '',
 614                      'massupdate_mail_icon' =>''
 615                  ));
 616              }
 617  
 618              $this->t->set_var('CATEGORY',$GLOBALS['egw']->strip_html($category));
 619  
 620              $this->t->fp('LIST_HDR','list_header');
 621              $this->t->fp('LIST_FTR','list_footer');
 622              $this->t->fp('CONTENT','list_section',TRUE);
 623              $this->t->set_var('LIST_ITEMS','');
 624          }
 625  
 626  		function print_list($where_clause, $start, $bm_cat, &$content)
 627          {
 628              $page_header_shown = $GLOBALS['page_header_shown'];
 629  
 630              $this->t->set_file(array(
 631                  'list' => 'list.tpl'
 632              ));
 633              $this->t->set_block('list','list_section');
 634              $this->t->set_block('list','list_header');
 635              $this->t->set_block('list','list_footer');
 636              $this->t->set_block('list','list_item');
 637              $this->t->set_block('list','list_keyw');
 638              $this->t->set_block('list','page_header');
 639              $this->t->set_block('list','page_footer');
 640  
 641              $this->t->set_var('list_mass_select_form',$GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.mass'));
 642  
 643              if (! $page_header_shown)
 644              {
 645                  $this->t->fp('header','page_header');
 646                  $page_header_shown = True;
 647              }
 648              else
 649              {
 650                  $this->t->set_var('header','');
 651              }
 652  
 653              $bm_list = $this->bo->_list($bm_cat,$start,$where_clause);
 654  
 655              $prev_category_id = -1;
 656              $rows_printed = 0;
 657  
 658              while (list($bm_id,$bookmark) = @each($bm_list))
 659              {
 660                  $rows_printed++;
 661  
 662                  if ($bookmark['category'] != $prev_category_id)
 663                  {
 664                      if ($rows_printed > 1)
 665                      {
 666                          $this->print_list_break($prev_category_id);
 667                      }
 668                      $prev_category_id       = $bookmark['category'];
 669                  }
 670  
 671                  if ($bookmark['keywords'])
 672                  {
 673                      $this->t->set_var(BOOKMARK_KEYW, $bookmark['keywords']);
 674                      $this->t->parse('bookmark_keywords','list_keyw');
 675                  }
 676                  else
 677                  {
 678                      $this->t->set_var('bookmark_keywords','');
 679                  }
 680  
 681                  // Check owner
 682                  if ($this->bo->check_perms2($bookmark['owner'],$bookmark['access'],EGW_ACL_EDIT))
 683                  {
 684                      $maintain_url  = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.edit&bm_id=' . $bm_id);
 685                      $maintain_link = sprintf(
 686                          '<a href="%s"><img src="%s" align="top" border="0" alt="%s"></a>',
 687                          $maintain_url,
 688                          $this->img['edit'],
 689                          lang('Edit this bookmark')
 690                      );
 691                  }
 692                  else
 693                  {
 694                      $maintain_link = '';
 695                  }
 696  
 697                  $view_url      = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.view&bm_id=' . $bm_id);
 698                  $view_link     = sprintf(
 699                      '<a href="%s"><img src="%s" align="top" border="0" alt="%s"></a>',
 700                      $view_url,
 701                      $this->img['view'],
 702                      lang('View this bookmark')
 703                  );
 704  
 705                  $mail_link = sprintf(
 706                      '<a href="%s"><img align="top" border="0" src="%s" alt="%s"></a>',
 707                      $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.mail&bm_id='.$bm_id),
 708                      $this->img['mail'],
 709                      lang('Mail this bookmark')
 710                  );
 711  
 712                  $this->t->set_var(array(
 713                      'maintain_link' => $maintain_link,
 714                      'bookmark_url' => $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.redirect&bm_id='.$bm_id),
 715                      'view_link' => $view_link,
 716                      'mail_link' => $mail_link,
 717                      'checkbox' => '<input type="checkbox" name="item_cb[]" value="' . $bm_id . '">',
 718                      'bookmark_name' => $bookmark['name'],
 719                      'bookmark_desc' => nl2br($bookmark['desc']),
 720                      'bookmark_rating' => sprintf('<img src="%s/bar-%s.jpg">',EGW_IMAGES,$bookmark['rating'])
 721                  ));
 722                  $this->t->parse(LIST_ITEMS,'list_item',True);
 723              }
 724  
 725              if ($rows_printed > 0)
 726              {
 727                  $this->print_list_break($prev_category_id);
 728                  $content = $this->t->get('CONTENT');
 729                  $this->t->fp('footer','page_footer');
 730              }
 731          }
 732  
 733  		function tree()
 734          {
 735              $this->location_info['returnto'] = 'tree';
 736              unset($this->location_info['returnto2']);
 737              $this->bo->save_session_data($this->location_info);
 738  
 739              if ($_COOKIE['menutree'])
 740              {
 741                  $this->expandedcats = array_keys($_COOKIE['menutree']);
 742              }
 743              else
 744              {
 745                  $this->expandedcats = Array();
 746              }
 747  
 748              $GLOBALS['egw']->common->egw_header();
 749              echo parse_navbar();
 750              $this->app_header(TREE);
 751  
 752              $this->t->set_file(array(
 753                  'common_' => 'common.tpl',
 754              ));
 755              $this->t->set_var(Array(
 756                  'th_bg' => $GLOBALS['egw_info']['theme']['th_bg']
 757              ));
 758  
 759              $categories = $this->bo->categories->return_array('mains',0,False,'','cat_name','',True);
 760  
 761              $tree = "<script type='text/javascript'>
 762  // the whole thing only works in a DOM capable browser or IE 4*/
 763  
 764  function add(catid)
 765  {
 766      document.cookie = 'menutree[' + catid + ']=';
 767  }
 768  
 769  function remove(catid)
 770  {
 771      var now =new Date();
 772      document.cookie = 'menutree[' + catid + ']=; expires=' + now.toGMTString();
 773  }
 774  
 775  function toggle(image, catid)
 776  {
 777      if (document.getElementById)
 778      { //DOM capable
 779          styleObj = document.getElementById(catid);
 780      }
 781      else //we're helpless
 782      {
 783          return
 784      }
 785      if (styleObj)    // if an object is found
 786      {
 787          if (styleObj.style.display == 'none')
 788          {
 789              add(catid);
 790              image.src = '" . $this->img['collapse'] . "';
 791              styleObj.style.display = 'block';
 792          }
 793          else
 794          {
 795              remove(catid);
 796              image.src = '" . $this->img['expand'] . "';
 797              styleObj.style.display = 'none';
 798          }
 799      }
 800  }
 801  </script>" .
 802                  '<table border="0" cellspacing="0" cellpadding="0" width="100%">' .
 803                  $this->showcat($categories) .
 804                  '</table>' .
 805                  "\n";
 806  
 807              $this->t->set_var('body',$tree);
 808              $this->app_messages($this->t);
 809              $this->t->pfp('out','common_');
 810          }
 811  
 812  		function showcat($cats)
 813          {
 814              while(list(,$cat) = @each($cats))
 815              {
 816                  $cat_id = $cat['id'];
 817                  $status = in_array($cat_id,$this->expandedcats);
 818                  $tree .= "\n" .
 819                      '<tr><td width="10%">' .
 820                      '<img src="' .
 821                      $this->img[$status ? "collapse" : "expand"] .
 822                      '" onclick="toggle(this, \'' .
 823                      $cat_id .
 824                      '\')"></td><td><a style="font-weight:bold" title="' .
 825                      $GLOBALS['egw']->strip_html($cat['description']) .
 826                      '" href="' .
 827                      $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui._list&start=0&bm_cat=' . $cat_id) .
 828                      '">' .
 829                      $GLOBALS['egw']->strip_html($cat['name']) .
 830                      '</a></td></tr>' .
 831                      "\n";
 832                  $subcats = $this->bo->categories->return_array('subs',0,False,'','','',True,$cat_id);
 833                  $bookmarks = $this->bo->_list($cat_id,False,False,False);
 834                  if ($subcats || $bookmarks)
 835                  {
 836                      $tree .= '<tr><td></td><td><table style="display:' .
 837                          ($status ? "block" : "none") .
 838                          '" border="0" cellspacing="0" cellpadding="0" width="100%" id="'.
 839                          $cat_id .
 840                          '">';
 841  
 842                      while(list($bm_id,$bookmark) = @each($bookmarks))
 843                      {
 844                          $tree .= '<tr><td colspan="2">';
 845                          if ($this->bo->check_perms2($bookmark['owner'],$bookmark['access'],EGW_ACL_EDIT))
 846                          {
 847                              $maintain_url  = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.edit&bm_id=' . $bm_id);
 848                              $maintain_link = sprintf(
 849                                  '<a href="%s"><img src="%s" align="top" border="0" alt="%s"></a>',
 850                                  $maintain_url,
 851                                  $this->img['edit'],
 852                                  lang('Edit this bookmark')
 853                              );
 854                          }
 855                          else
 856                          {
 857                              $maintain_link = '';
 858                          }
 859  
 860                          $view_url      = $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.view&bm_id=' . $bm_id);
 861                          $view_link     = sprintf(
 862                              '<a href="%s"><img src="%s" align="top" border="0" alt="%s"></a>',
 863                              $view_url,
 864                              $this->img['view'],
 865                              lang('View this bookmark')
 866                          );
 867  
 868                          $redirect_link = '<a href="' .
 869                              $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.redirect&bm_id='.$bm_id) .
 870                              '" target="_new">' . $bookmark['name'] . '</a>';
 871  
 872                          $tree .= $maintain_link . $view_link . $redirect_link .
 873                              '</td></tr>';
 874                      }
 875  
 876                      if ($subcats)
 877                      {
 878                          $tree .= $this->showcat($subcats);
 879                      }
 880  
 881                      $tree .= '</table></td></tr>';
 882                  }
 883              }
 884              return $tree;
 885          }
 886  
 887  		function view()
 888          {
 889              if (isset($_GET['bm_id']))
 890              {
 891                  $bm_id = $_GET['bm_id'];
 892              }
 893              elseif (is_array($this->location_info))
 894              {
 895                  $bm_id = $this->location_info['bm_id'];
 896              }
 897              //if the user cancelled we go back to the view we came from
 898              if ($_POST['cancel_x'] || $_POST['cancel_y'])
 899              {
 900                  unset($this->location_info['returnto2']);
 901                  $this->init();
 902                  return;
 903              }
 904              //delete bookmark and go back to view we came from
 905              if ($_POST['delete_x'] || $_POST['delete_y'])
 906              {
 907                  $this->bo->delete($bm_id);
 908                  unset($this->location_info['returnto2']);
 909                  $this->init();
 910                  return;
 911              }
 912              if ($_POST['edit_x'] || $_POST['edit_y'])
 913              {
 914                  $this->edit();
 915                  return;
 916              }
 917              if ($_POST['edit_category_x'] || $_POST['edit_category_y'])
 918              {
 919                  $GLOBALS['egw']->redirect_link('/index.php','menuaction=preferences.uicategories.index&cats_app=bookmarks&cats_level=True&global_cats=True');
 920                  return;
 921              }
 922  
 923              $bookmark = $this->bo->read($bm_id);
 924  
 925              if (!$bookmark[EGW_ACL_READ])
 926              {
 927                  $this->bo->error_msg = lang('Bookmark not readable');
 928                  unset($this->location_info['returnto2']);
 929                  $this->init();
 930                  return;
 931              }
 932  
 933              //store the view we are in
 934              $this->location_info['returnto2'] = 'view';
 935              $this->location_info['bm_id'] = $bm_id;
 936              $this->bo->save_session_data($this->location_info);
 937  
 938              $GLOBALS['egw']->common->egw_header();
 939              echo parse_navbar();
 940              $this->app_header();
 941  
 942              $this->t->set_file(array(
 943                  'common_' => 'common.tpl',
 944                  'form'     => 'form.tpl',
 945              ));
 946  
 947              $this->t->set_block('form','body');
 948              $this->t->set_block('form','form_info');
 949  
 950              $this->bo->date_information($this->t,$bookmark['info']);
 951              $this->app_template();
 952  
 953              $account =& CreateObject('phpgwapi.accounts',$bookmark['owner']);
 954              $ad      = $account->read_repository();
 955              $category  = $GLOBALS['egw']->strip_html($this->bo->categories->id2name($bookmark['category']));
 956  
 957              $this->t->set_var(array(
 958                  'total_visits' => $bookmark['visits'],
 959                  'owner_value' => $GLOBALS['egw']->common->display_fullname($ad['account_lid'],$ad['firstname'],$ad['lastname'])
 960              ));
 961              $this->t->parse('info','form_info');
 962              $this->t->set_var(array(
 963                  'form_info' => '',
 964                  'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.view&bm_id=' . $bm_id),
 965                  'lang_access' => lang('Access'),
 966                  'input_access' => lang($bookmark['access']),
 967                  'lang_header' => lang('View bookmark'),
 968                  'input_url' => ('<a href="' . $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.redirect&bm_id='.$bm_id) .
 969                      '" target="_new">' . $bookmark['url'] . '</a>'
 970                  ),
 971                  'input_name' => $bookmark['name'],
 972                  'input_desc' => nl2br($bookmark['desc']),
 973                  'input_keywords' => $bookmark['keywords'],
 974                  'input_rating' => ('<img src="' . $GLOBALS['egw']->common->get_image_path('bookmarks') .
 975                      '/bar-' . $bookmark['rating'] . '.jpg">'
 976                  ),
 977                  'input_category' => $category,
 978                  'edit_button' => ($this->bo->check_perms($bm_id,EGW_ACL_EDIT) ?
 979                      ('<input type="image" name="edit" title="' . lang('Edit') . '" src="'
 980                          . $GLOBALS['egw']->common->image('bookmarks','edit') . '" border="0">'
 981                      ) :
 982                  ''
 983                  ),
 984                  'delete_button' => ($this->bo->check_perms($bm_id,EGW_ACL_DELETE) ?
 985                      ('<input type="image" name="delete" title="' . lang('Delete') . '" src="'
 986                          . $GLOBALS['egw']->common->image('bookmarks','delete') . '" border="0">'
 987                      ) :
 988                      ''
 989                  )
 990              ));
 991              $this->t->fp('body','form');
 992              $this->app_messages($this->t);
 993              $this->t->pfp('out','common_');
 994          }
 995  
 996  		function mail()
 997          {
 998              $GLOBALS['egw']->common->egw_header();
 999              echo parse_navbar();
1000              $this->app_header();
1001  
1002              $this->t->set_file(array(
1003                  'common_' => 'common.tpl',
1004                  'mail'    => 'maillink.body.tpl'
1005              ));
1006  
1007              if ($_POST['send'])    // Send button clicked
1008              {
1009                  $validate =& CreateObject('phpgwapi.validator');
1010                  // Strip space and tab from anywhere in the To field
1011                  $to = $validate->strip_space($_POST['to']);
1012  
1013                  // Trim the subject
1014                  $subject = $GLOBALS['egw']->strip_html(trim($_POST['subject']));
1015  
1016                  $message = $GLOBALS['egw']->strip_html($_POST['message']);
1017  
1018                  // Do we have all necessary data?
1019                  if (empty($to) || empty($subject) || empty($message))
1020                  {
1021                      $this->bo->error_msg .= '<br>'.lang('Please fill out <B>To E-Mail Address</B>, <B>Subject</B>, and <B>Message</B>!');
1022                  }
1023                  else
1024                  {
1025                      // the To field may contain one or more email addresses
1026                      // separated by commas. Check each one for proper format.
1027                      $to_array = explode(",", $to);
1028  
1029                      while (list($key, $val) = each($to_array))
1030                      {
1031                          // Is email address in the proper format?
1032                          if (!$validate->is_email($val))
1033                          {
1034                              $this->bo->error_msg .= '<br>' .
1035                                  lang('To address %1 invalid. Format must be <strong>user@domain</strong> and domain must exist!',$val).
1036                                  '<br><small>'.$validate->ERROR.'</small>';
1037                              break;
1038                          }
1039                      }
1040                  }
1041                  if (!isset ($this->bo->error_msg))
1042                  {
1043                      $send     =& CreateObject('phpgwapi.send');
1044  
1045                      $from = $GLOBALS['egw_info']['user']['fullname'] . ' <'.$GLOBALS['egw_info']['user']['email'].'>';
1046  
1047                      // send the message
1048                      $send->msg('email',$to,$subject,$message ."\n". $this->bo->config['mail_footer'],'','','',$from);
1049                      $this->bo->msg .= '<br>'.lang('mail-this-link message sent to %1.',$to);
1050                  }
1051              }
1052  
1053              if (empty($subject))
1054              {
1055                  $subject = lang('Found a link you might like');
1056              }
1057  
1058              if (empty($message))
1059              {
1060                  if (is_array($_POST['item_cb']))
1061                  {
1062                      while (list(,$id) = each($_POST['item_cb']))
1063                      {
1064                          $bookmark = $this->bo->read($id);
1065                          $links[] = array(
1066                              'name' => $bookmark['name'],
1067                              'url'  => $bookmark['url']
1068                      );
1069                      }
1070                  }
1071                  else
1072                  {
1073                      $bookmark = $this->bo->read($_GET['bm_id']);
1074                      $links[] = array(
1075                          'name' => $bookmark['name'],
1076                          'url'  => $bookmark['url']
1077                      );
1078                  }
1079                  $message = lang('I thought you would be interested in the following link(s):')."\n";
1080                  while (list(,$link) = @each($links))
1081                  {
1082                      $message .= sprintf("%s - %s\n",$link['name'],$link['url']);
1083                  }
1084              }
1085  
1086              $this->t->set_var(array(
1087                  'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
1088                  'header_message' => lang('Send bookmark'),
1089                  'lang_from' => lang('Message from'),
1090                  'lang_to' => lang('To E-Mail Addresses'),
1091                  'lang_multiple_addr' => lang('(comma separate multiple addresses)'),
1092                  'lang_subject' => lang('Subject'),
1093                  'lang_message' => lang('Message'),
1094                  'lang_send' => lang('Send'),
1095                  'from_name' => $GLOBALS['egw']->common->display_fullname(),
1096                  'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.mail'),
1097                  'to' => $to,
1098                  'subject' => $subject,
1099                  'message' => $message
1100              ));
1101              $this->t->fp('body','mail');
1102              $this->app_messages();
1103              $this->t->pfp('out','common_');
1104          }
1105  
1106  		function mass()
1107          {
1108              $item_cb = $_POST['item_cb'];
1109              if ($_POST['delete_x'] || $_POST['delete_y'])
1110              {
1111                  if (is_array($item_cb))
1112                  {
1113                      $i = 0;
1114                      while (list(,$id) = each($item_cb))
1115                      {
1116                          if ($this->bo->delete($id))
1117                          {
1118                              $i++;
1119                          }
1120                      }
1121                      $this->bo->msg = lang('%1 bookmarks have been deleted',$i);
1122                  }
1123  
1124                  $this->_list();
1125              }
1126              elseif ($_POST['mail_x'] || $_POST['mail_y'])
1127              {
1128                  $this->mail();
1129              }
1130          }
1131  
1132  		function redirect()
1133          {
1134              $bm_id = $_GET['bm_id'];
1135              $bookmark = $this->bo->read($bm_id,False);    // dont htmlspecialchars the url (!)
1136              $ts = explode(",",$bookmark['info']);
1137              $newtimestamp = sprintf("%s,%s,%s",$ts[0],time(),$ts[2]);
1138              $this->bo->updatetimestamp($bm_id,$newtimestamp);
1139              $GLOBALS['egw']->redirect($bookmark['url']);
1140          }
1141  
1142  		function export()
1143          {
1144              if ($_POST['export'])
1145              {
1146                  #  header("Content-type: text/plain");
1147                  header("Content-type: application/octet-stream");
1148  
1149                  if ($_POST['exporttype'] == 'Netscape/Mozilla')
1150                  {
1151                      header("Content-Disposition: attachment; filename=bookmarks.html");
1152                      echo $this->bo->export($_POST['bookmark']['category'],'ns');
1153                  }
1154                  else
1155                  {
1156                      header("Content-Disposition: attachment; filename=bookmarks.xbel");
1157                      echo $this->bo->export($_POST['bookmark']['category'],'xbel');
1158                  }
1159              }
1160              else
1161              {
1162                  $GLOBALS['egw']->common->egw_header();
1163                  echo parse_navbar();
1164                  $this->t->set_file('body','export.body.tpl');
1165                  $this->t->set_var(Array(
1166                      'FORM_ACTION' => $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.export'),
1167                      'input_categories' => $this->bo->categories_list(0,True),
1168                      'lang_categories' => lang('Please select the categories to export'),
1169                      'lang_format' => lang('Select the format you would like to export to'),
1170                      'lang_export_bookmarks' => lang('Export bookmarks'),
1171                  ));
1172                  $this->t->pfp('out','body');
1173                  $GLOBALS['egw']->common->egw_footer();
1174              }
1175          }
1176  
1177  		function import()
1178          {
1179              if ($_POST['import'])
1180              {
1181                  $this->bo->import($_FILES['bkfile'],$_POST['bookmark']['category']);
1182              }
1183  
1184              $GLOBALS['egw']->common->egw_header();
1185              echo parse_navbar();
1186              $this->t->set_file('body','import.body.tpl');
1187              $this->t->set_var(Array(
1188                  'FORM_ACTION' => $GLOBALS['egw']->link('/index.php','menuaction=bookmarks.ui.import'),
1189                  'lang_name' => lang('Enter the name of the Netscape bookmark file<br>that you want imported into bookmarker below.'),
1190                  'lang_file' => lang('Netscape Bookmark File'),
1191                  'lang_import_button' => lang('Import Bookmarks'),
1192                  'lang_note' => lang('<b>Note:</b> This currently works with netscape bookmarks only'),
1193                  'lang_catchoose' => lang('To which category should the imported folder hierarchy be attached'),
1194                  'input_categories' => $this->bo->categories_list(0),
1195              ));
1196              $this->app_messages();
1197              $this->t->pfp('out','body');
1198              $GLOBALS['egw']->common->egw_footer();
1199          }
1200      }


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