home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / contacts / index.php < prev    next >
Encoding:
PHP Script  |  2004-01-15  |  5.4 KB  |  175 lines

  1. <?php /* $Id: index.php,v 1.20 2004/01/15 17:53:02 gregorerhardt Exp $ */
  2. $AppUI->savePlace();
  3.  
  4. // To configure an aditional filter to use in the search string
  5. $additional_filter = "";
  6. // retrieve any state parameters
  7. if (isset( $_GET['where'] )) {
  8.     $AppUI->setState( 'ContIdxWhere', $_GET['where'] );
  9. }
  10. if (isset( $_GET["search_string"] )){
  11.     $AppUI->setState ('ContIdxWhere', "%".$_GET['search_string']);
  12.                 // Added the first % in order to find instrings also
  13.     $additional_filter = "OR contact_first_name like '%{$_GET['search_string']}%'
  14.                           OR contact_last_name  like '%{$_GET['search_string']}%'
  15.                           OR contact_company    like '%{$_GET['search_string']}%'
  16.                           OR contact_notes      like '%{$_GET['search_string']}%'
  17.                           OR contact_email      like '%{$_GET['search_string']}%'";
  18. }
  19. $where = $AppUI->getState( 'ContIdxWhere' ) ? $AppUI->getState( 'ContIdxWhere' ) : '%';
  20.  
  21. $orderby = 'contact_order_by';
  22.  
  23. // Pull First Letters
  24. $let = ":";
  25. $sql = "
  26. SELECT DISTINCT UPPER(SUBSTRING($orderby,1,1)) as L
  27. FROM contacts
  28. WHERE contact_private=0
  29.     OR (contact_private=1 AND contact_owner=$AppUI->user_id)
  30.     OR contact_owner IS NULL OR contact_owner = 0
  31. ";
  32. $arr = db_loadList( $sql );
  33. foreach( $arr as $L ) {
  34.     $let .= $L['L'];
  35. }
  36.  
  37. // optional fields shown in the list (could be modified to allow breif and verbose, etc)
  38. $showfields = array(
  39.     // "test" => "concat(contact_first_name,' ',contact_last_name) as test",    why do we want the name repeated?
  40.     "contact_company" => "contact_company",
  41.     "contact_phone" => "contact_phone",
  42.     "contact_email" => "contact_email"
  43. );
  44.  
  45. // assemble the sql statement
  46. $sql = "SELECT contact_id, contact_order_by, ";
  47. foreach ($showfields as $val) {
  48.     $sql.="$val,";
  49. }
  50. $sql.= "contact_first_name, contact_last_name, contact_phone
  51. FROM contacts
  52. WHERE (contact_order_by LIKE '$where%' $additional_filter)
  53.     AND (contact_private=0
  54.         OR (contact_private=1 AND contact_owner=$AppUI->user_id)
  55.         OR contact_owner IS NULL OR contact_owner = 0
  56.     )
  57. ORDER BY $orderby
  58. ";
  59.  
  60. $carr[] = array();
  61. $carrWidth = 4;
  62. $carrHeight = 4;
  63.  
  64. $res = db_exec( $sql );
  65. $rn = db_num_rows( $res );
  66.  
  67. $t = floor( $rn / $carrWidth );
  68. $r = ($rn % $carrWidth);
  69.  
  70. if ($rn < ($carrWidth * $carrHeight)) {
  71.     for ($y=0; $y < $carrWidth; $y++) {
  72.         $x = 0;
  73.         //if($y<$r)    $x = -1;
  74.         while (($x<$carrHeight) && ($row = db_fetch_assoc( $res ))){
  75.             $carr[$y][] = $row;
  76.             $x++;
  77.         }
  78.     }
  79. } else {
  80.     for ($y=0; $y < $carrWidth; $y++) {
  81.         $x = 0;
  82.         if($y<$r)    $x = -1;
  83.         while(($x<$t) && ($row = db_fetch_assoc( $res ))){
  84.             $carr[$y][] = $row;
  85.             $x++;
  86.         }
  87.     }
  88. }
  89.  
  90. $tdw = floor( 100 / $carrWidth );
  91.  
  92. /**
  93. * Contact search form
  94. */
  95.  // Let's remove the first '%' that we previously added to ContIdxWhere
  96. $default_search_string = dPformSafe(substr($AppUI->getState( 'ContIdxWhere' ), 1, strlen($AppUI->getState( 'ContIdxWhere' ))), true);
  97.  
  98. $form = "<form action='./index.php' method='get'>".$AppUI->_('Search for')."
  99.            <input type='text' name='search_string' value='$default_search_string' />
  100.            <input type='hidden' name='m' value='contacts' />
  101.            <input type='submit' value='>' />
  102.            <a href='./index.php?m=contacts&search_string='>".$AppUI->_('Reset search')."</a>
  103.          </form>";
  104. // En of contact search form
  105.  
  106. $a2z = "\n<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\">";
  107. $a2z .= "\n<tr>";
  108. $a2z .= "<td width='100%' align='right'>" . $AppUI->_('Show'). ": </td>";
  109. $a2z .= '<td><a href="./index.php?m=contacts&where=0">' . $AppUI->_('All') . '</a></td>';
  110. for ($c=65; $c < 91; $c++) {
  111.     $cu = chr( $c );
  112.     $cell = strpos($let, "$cu") > 0 ?
  113.         "<a href=\"?m=contacts&where=$cu\">$cu</a>" :
  114.         "<font color=\"#999999\">$cu</font>";
  115.     $a2z .= "\n\t<td>$cell</td>";
  116. }
  117. $a2z .= "\n</tr>\n<tr><td colspan='28'>$form</td></tr></table>";
  118.  
  119.  
  120. // setup the title block
  121. $contact_id = $carr[$z][$x]["contact_id"];
  122. $titleBlock = new CTitleBlock( 'Contacts', 'monkeychat-48.png', $m, "$m.$a" );
  123. $titleBlock->addCell( $a2z );
  124. if ($canEdit) {
  125.     $titleBlock->addCell(
  126.         '<input type="submit" class="button" value="'.$AppUI->_('new contact').'">', '',
  127.         '<form action="?m=contacts&a=addedit" method="post">', '</form>'
  128.     );
  129.     $titleBlock->addCrumbRight(
  130.  
  131.         '<a href="./index.php?m=contacts&a=vcardimport&dialog=0">' . $AppUI->_('Import vCard') . '</a>'
  132.     );
  133. }
  134. $titleBlock->show();
  135. ?>
  136. <table width="100%" border="0" cellpadding="1" cellspacing="1" height="400" class="contacts">
  137. <tr>
  138. <?php
  139.     for ($z=0; $z < $carrWidth; $z++) {
  140. ?>
  141.     <td valign="top" align="left" bgcolor="#f4efe3" width="<?php echo $tdw;?>%">
  142.     <?php
  143.         for ($x=0; $x < @count($carr[$z]); $x++) {
  144.     ?>
  145.         <table width="100%" cellspacing="1" cellpadding="1">
  146.         <tr>
  147.             <td width="100%">
  148.                 <a href="./index.php?m=contacts&a=addedit&contact_id=<?php echo $carr[$z][$x]["contact_id"];?>"><strong><?php echo $carr[$z][$x]["contact_order_by"];?></strong></a> 
  149.                  <a  title="<?php echo $AppUI->_('Export vCard for').' '.$carr[$z][$x]["contact_first_name"].' '.$carr[$z][$x]["contact_last_name"]; ?>" href='./index.php?m=contacts&a=vcardexport&suppressHeaders=true&contact_id=<?php echo $carr[$z][$x]["contact_id"];?>' >(vCard)</a>
  150.             </td>
  151.         </tr>
  152.         <tr>
  153.             <td class="hilite">
  154.             <?php
  155.                 reset( $showfields );
  156.                 while (list( $key, $val ) = each( $showfields )) {
  157.                     if (strlen( $carr[$z][$x][$key] ) > 0) {
  158.                         if($val == "contact_email") {
  159.                           echo "<A HREF='mailto:{$carr[$z][$x][$key]}' class='mailto'>{$carr[$z][$x][$key]}</a>\n";
  160.                         } else {
  161.                           echo  $carr[$z][$x][$key]. "<br />";
  162.                         }
  163.                     }
  164.                 }
  165.             ?>
  166.             </td>
  167.         </tr>
  168.         </table>
  169.         <br /> <br />
  170.     <?php }?>
  171.     </td>
  172. <?php }?>
  173. </tr>
  174. </table>
  175.