[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Webmails/ -> ListView.php (source)

   1  <?php
   2  /*********************************************************************************
   3   ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4    * ("License"); You may not use this file except in compliance with the License
   5    * The Initial Developer of the Original Code is FOSS Labs.
   6    * Portions created by FOSS Labs are Copyright (C) FOSS Labs.
   7    * Portions created by vtiger are Copyright (C) vtiger.
   8    * All Rights Reserved.
   9    *
  10    ********************************************************************************/
  11  
  12  // figure out which page we are on and what mailbox we want to view
  13  if($_REQUEST["mailbox"] && $_REQUEST["mailbox"] != "") {$mailbox=$_REQUEST["mailbox"];} else {$mailbox="INBOX";}
  14  if($_REQUEST["start"] && $_REQUEST["start"] != "") {$start=$_REQUEST["start"];} else {$start="1";}
  15  $show_hidden=$_REQUEST["show_hidden"];
  16  
  17  global $current_user;
  18  require_once ('Smarty_setup.php');
  19  require_once ("data/Tracker.php");
  20  require_once('themes/'.$theme.'/layout_utils.php');
  21  require_once ('include/logging.php');
  22  require_once ('include/utils/utils.php');
  23  require_once ('include/utils/UserInfoUtil.php');
  24  require_once ("modules/Webmails/MailBox.php");
  25  require_once ("modules/Webmails/Webmail.php");
  26  require_once ("modules/Webmails/MailParse.php");
  27  
  28  $MailBox = new MailBox($mailbox);
  29  
  30  // Check for a valid mailbox and also make sure the needed php_imap module is installed
  31  $mods = parsePHPModules();
  32  
  33  if(!$MailBox->mbox || !isset($mods["imap"]) || $mods["imap"] == "") {
  34      echo "<center><font color='red'><h3>Please configure your mail settings</h3></font></center>";
  35      exit();
  36  }
  37  
  38  // Set the system into degraded service mode where needed
  39  $degraded_service='false';
  40  if($MailBox->mail_protocol == "imap" || $MailBox->mail_protocol == "pop3")
  41      $degraded_service='true';
  42  
  43  
  44  if($_POST["command"] == "check_mbox_all") {
  45      exit();
  46          $boxes = array();
  47          $i=0;
  48          foreach ($_SESSION["mailboxes"] as $key => $val) {
  49                  $MailBox = new MailBox($key);
  50                  $box = imap_status($MailBox->mbox, "{".$MailBox->imapServerAddress."}".$key, SA_ALL);
  51  
  52                  $boxes[$i]["name"] = $key;
  53                  if($val == $box->unseen)
  54                          $boxes[$i]["newmsgs"] = 0;
  55                  elseif($val < $box->unseen) {
  56                          $boxes[$i]["newmsgs"] = ($box->unseen-$val);
  57                          $_SESSION["mailboxes"][$key] = $box->unseen;
  58                  } else {
  59                          $boxes[$i]["newmsgs"] = 0;
  60                          $_SESSION["mailboxes"][$key] = $box->unseen;
  61                  }
  62                  $i++;
  63                  imap_close($MailBox->mbox);
  64          }
  65  
  66          $ret = '';
  67          if(count($boxes) > 0) {
  68                  $ret = '{"msgs":[';
  69                  for($i=0,$num=count($boxes);$i<$num;$i++) {
  70                          $ret .= '{"msg":';
  71                          $ret .= '{';
  72                          $ret .= '"box":"'.$boxes[$i]["name"].'",';
  73                          $ret .= '"newmsgs":"'.$boxes[$i]["newmsgs"].'"}';
  74  
  75                          if(($i+1) == $num)
  76                                  $ret .= '}';
  77                          else
  78                                  $ret .= '},';
  79                  }
  80                  $ret .= ']}';
  81          }
  82          echo $ret;
  83          flush();
  84          exit();
  85  }
  86  
  87  if($_POST["command"] == "check_mbox") {
  88          $adb->println("Inside check_mbox AJAX command");
  89  
  90          $search = imap_search($MailBox->mbox, "ALL NEW");
  91          if($search === false) {echo "failed";flush();exit();}
  92  
  93          $data = imap_fetch_overview($MailBox->mbox,implode(',',$search));
  94          $num=sizeof($data);
  95  
  96          $ret = '';
  97          if($num > 0) {
  98                  $ret = '{"mails":[';
  99                  for($i=0;$i<$num;$i++) {
 100                          $ret .= '{"mail":';
 101                          $ret .= '{';
 102                          $ret .= '"mailid":"'.$data[$i]->msgno.'",';
 103                          $ret .= '"subject":"'.substr($data[$i]->subject,0,40).'",';
 104                          $ret .= '"date":"'.substr($data[$i]->date,0,30).'",';
 105                          $ret .= '"from":"'.substr($data[$i]->from,0,20).'",';
 106                          $ret .= '"to":"'.$data[$i]->to.'",';
 107                          $email = new Webmail($MailBox->mbox,$data[$i]->msgno);
 108                          if($email->has_attachments)
 109                                  $ret .= '"attachments":"1"}';
 110                          else
 111                                  $ret .= '"attachments":"0"}';
 112                          if(($i+1) == $num)
 113                                  $ret .= '}';
 114                          else
 115                                  $ret .= '},';
 116                  }
 117                  $ret .= ']}';
 118          }
 119  
 120          echo $ret;
 121          flush();
 122          imap_close($MailBox->mbox);
 123      exit();
 124  }
 125  
 126  ?>
 127  <script language="JavaScript" type="text/javascript" src="include/scriptaculous/prototype.js"></script>
 128  <script language="JavaScript" type="text/javascript" src="include/scriptaculous/scriptaculous.js?load=effects,builder"></script>
 129  
 130  <script type="text/javascript">
 131  // Pass our PHP variables to js.
 132  <?php if($degraded_service == 'true') { echo 'var degraded_service="true";';}else{echo 'var degraded_service="false";';};?>
 133  var mailbox = "<?php echo $MailBox->mailbox;?>";
 134  var box_refresh=<?php echo $MailBox->box_refresh;?>;
 135  var webmail = new Array();
 136  var timer;
 137  var command;
 138  var id;
 139  
 140  
 141  addOnloadEvent(function() {
 142          window.setTimeout("periodic_event()",box_refresh);
 143      }
 144  );
 145  </script>
 146  <script language="JavaScript" type="text/javascript" src="modules/Webmails/webmails.js"></script>
 147  <?
 148  
 149  global $displayed_msgs;
 150  // AJAX commands (should be moved)
 151  if($_POST["command"] == "move_msg" && $_POST["ajax"] == "true") {
 152      imap_mail_move($MailBox->mbox,$_REQUEST["mailid"],$_REQUEST["mvbox"]);
 153      imap_close($MailBox->mbox);
 154      echo "SUCCESS";
 155      flush();
 156      exit();
 157  }
 158  
 159  // Function to remove directories used for tmp attachment storage
 160  function SureRemoveDir($dir) {
 161     if(!$dh = @opendir($dir)) return;
 162     while (($obj = readdir($dh))) {
 163       if($obj=='.' || $obj=='..') continue;
 164       if (!@unlink($dir.'/'.$obj)) {
 165           SureRemoveDir($dir.'/'.$obj);
 166       } else {
 167           $file_deleted++;
 168       }
 169     }
 170     if (@rmdir($dir)) $dir_deleted++;
 171  }
 172  $save_path='/usr/local/share/vtiger/modules/Webmails/tmp';
 173  $user_dir=$save_path."/".$_SESSION["authenticated_user_id"];
 174  
 175  // Get the list of mails for this mailbox
 176  $elist = $MailBox->mailList;
 177  $numEmails = $elist["count"];
 178  $headers = $elist["headers"];
 179  
 180  if($start == 1 || $start == "") {
 181      $start_message=$numEmails;
 182  } else {
 183      $start_message=($numEmails-($start*$mails_per_page));
 184  }
 185  $c=$numEmails;
 186  
 187  if(!isset($_REQUEST["search"])) {
 188      $numPages = round($numEmails/$MailBox->mails_per_page);
 189      if($numPages > 1) {
 190          $navigationOutput = "<a href='index.php?module=Webmails&action=index&start=1&mailbox=".$mailbox."'><img src='modules/Webmails/images/start.gif' border='0'></a>&nbsp;&nbsp;";
 191          $navigationOutput .= "<a href='index.php?module=Webmails&action=index&start=".($start-1)."&mailbox=".$mailbox."'><img src='modules/Webmails/images/previous.gif' border='0'></a> &nbsp;";
 192          $navigationOutput .= "<a href='index.php?module=Webmails&action=index&start=".($start+1)."&mailbox=".$mailbox."'><img src='modules/Webmails/images/next.gif' border='0'></a>&nbsp;&nbsp;";
 193          $navigationOutput .= "<a href='index.php?module=Webmails&action=index&start=".$numPages."&mailbox=".$mailbox."'><img src='modules/Webmails/images/end.gif' border='0'></a>";
 194      }
 195  }
 196  
 197  $overview=$elist["overview"];
 198  ?>
 199  <!-- MAIN MSG LIST TABLE -->
 200  <script type="text/javascript">
 201  // Here we are creating a multi-dimension array to store mail info
 202  // these are mainly used in the preview window and could be ajaxified/
 203  // during the preview window load instead.
 204  var msgCount = "<?php echo $numEmails;?>";
 205  <?
 206  $mails = array();
 207  if (is_array($overview)) {
 208     foreach ($overview as $val) {
 209      $mails[$val->msgno] = $val;
 210      ?>
 211      webmail[<?php echo $val->msgno;?>] = new Array();
 212      webmail[<?php echo $val->msgno;?>]["from"]="<?php echo addslashes($val->from);?>";
 213      webmail[<?php echo $val->msgno;?>]["to"]="<?php echo addslashes($val->to);?>";
 214      webmail[<?php echo $val->msgno;?>]["subject"]="<?php echo addslashes($val->subject);?>";
 215      webmail[<?php echo $val->msgno;?>]["date"]="<?php echo addslashes($val->date);?>";
 216      <?
 217     }
 218  }
 219  echo "</script>";
 220  
 221  $listview_header = array("<th>Info</th>","<th>Subject</th>","<th>Date</th>","<th>From</th>","<th>Del</th>");
 222  $listview_entries = array();
 223  
 224  $displayed_msgs=0;
 225  $new_msgs=0;
 226  if(($numEmails-1) <= 0)
 227      $listview_entries[0][] = '<td colspan="6" width="100%" align="center"><b>No Emails In This Folder</b></td>';
 228  else {
 229  
 230  if(isset($_REQUEST["search"])) {
 231      $searchstring = $_REQUEST["search_type"].' "'.$_REQUEST["search_input"].'"';
 232      //echo $searchstring."<br>";
 233      $searchlist = imap_search($MailBox->mbox,$searchstring);
 234      if($searchlist === false)
 235            echo "The search failed";
 236  
 237      $num_searches = count($searchlist);
 238  
 239      //print_r($searchlist);
 240      $c=$numEmails;
 241  }
 242  
 243  flush();
 244  
 245  // MAIN LOOP
 246  // Main loop to create listview entries
 247  $i=1;
 248  while ($i<$c) {
 249      if(is_array($searchlist)) {
 250          for($l=0;$l<$num_searches;$l++) {
 251              if($mails[$start_message]->msgno == $searchlist[$l])
 252                  $listview_entries[] = show_msg($mails,$start_message);
 253          }
 254      } else {
 255          $listview_entries[] = show_msg($mails,$start_message);
 256          if($displayed_msgs == $MailBox->mails_per_page) {break;}
 257      }
 258        $i++;
 259        $start_message--;
 260  }
 261  }
 262  
 263  // Build folder list and move_to dropdown box
 264  $list = imap_getmailboxes($MailBox->mbox, "{".$MailBox->imapServerAddress."}", "*");
 265  sort($list);
 266  $i=0;
 267  if (is_array($list)) {
 268            $boxes = '<select name="mailbox" id="mailbox_select">';
 269          foreach ($list as $key => $val) {
 270          $tmpval = preg_replace(array("/\{.*?\}/i"),array(""),$val->name);
 271          if(preg_match("/trash/i",$tmpval))
 272              $img = "webmail_trash.gif";
 273          elseif(preg_match("/sent/i",$tmpval))
 274              $img = "webmail_uparrow.gif";
 275          else
 276              $img = "webmail_downarrow.gif";
 277  
 278          $i++;
 279  
 280          if ($_REQUEST["mailbox"] == $tmpval) {
 281                          $boxes .= '<option value="'.$tmpval.'" SELECTED>'.$tmpval;
 282              $_SESSION["mailboxes"][$tmpval] = $new_msgs;
 283  
 284              if($numEmails==0) {$num=$numEmails;} else {$num=($numEmails-1);}
 285              $folders .= '<li><img src="'.$image_path.'/'.$img.'" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\''.$tmpval.'\');" class="webMnu" onmouseover="show_remfolder(\''.$tmpval.'\');" onmouseout="show_remfolder(\''.$tmpval.'\');">'.$tmpval.'</a>&nbsp;&nbsp;<span id="'.$tmpval.'_count" style="font-weight:bold">(<span id="'.$tmpval.'_unread">'.$new_msgs.'</span> of <span id="'.$tmpval.'_read">'.$num.'</span>)</span>&nbsp;&nbsp;<span id="remove_'.$tmpval.'" style="position:relative;display:none">Remove</span></li>';
 286          } else {
 287              $box = imap_status($MailBox->mbox, "{".$MailBox->imapServerAddress."}".$tmpval, SA_ALL);
 288              $_SESSION["mailboxes"][$tmpval] = $box->unseen;
 289  
 290              if($box->messages==0) {$num=$box->messages;} else {$num=($box->messages-1);}
 291                            $boxes .= '<option value="'.$tmpval.'">'.$tmpval;
 292              $folders .= '<li><img src="'.$image_path.'/'.$img.'" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\''.$tmpval.'\');" class="webMnu">'.$tmpval.'</a>&nbsp;<span id="'.$tmpval.'_count" style="font-weight:bold">(<span id="'.$tmpval.'_unread">'.$box->unseen.'</span> of <span id="'.$tmpval.'_read">'.$num.'</span>)</span></li>';
 293          }
 294       }
 295          $boxes .= '</select>';
 296  }
 297  
 298  imap_close($MailBox->mbox);
 299  
 300  $smarty = new vtigerCRM_Smarty;
 301  $smarty->assign("USERID", $current_user->id);
 302  $smarty->assign("MOD", $mod_strings);
 303  $smarty->assign("APP", $app_strings);
 304  $smarty->assign("IMAGE_PATH",$image_path);
 305  $smarty->assign("LISTENTITY", $listview_entries);
 306  $smarty->assign("LISTHEADER", $listview_header);
 307  $smarty->assign("MODULE","Webmails");
 308  $smarty->assign("SINGLE_MOD",'Webmails');
 309  $smarty->assign("BUTTONS",$other_text);
 310  $smarty->assign("CATEGORY","My Home Page");
 311  $smarty->assign("NAVIGATION", $navigationOutput);
 312  $smarty->assign("FOLDER_SELECT", $boxes);
 313  $smarty->assign("NUM_EMAILS", $numEmails);
 314  $smarty->assign("MAILBOX", $MailBox->mailbox);
 315  $smarty->assign("ACCOUNT", $MailBox->display_name);
 316  $smarty->assign("BOXLIST",$folders);
 317  $smarty->assign("DEGRADED_SERVICE",$degraded_service);
 318  $smarty->display("Webmails.tpl");
 319  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7