Closes #682: Add search in contact list
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 15 Aug 2007 14:55:29 +0000 (14:55 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 15 Aug 2007 14:55:29 +0000 (14:55 +0000)
Fix issues with string encoding in backtrace

 ChangeLog                              |    3 +++
 classes/plbacktrace.php                |   13 +++++++++----
 classes/plset.php                      |    1 -
 htdocs/css/default.css                 |    2 +-
 htdocs/css/keynote.css                 |    2 +-
 include/userset.inc.php                |   17 ++++++++++++++---
 modules/carnet.php                     |   11 ++++++++++-
 modules/search/classes.inc.php         |    1 +
 templates/carnet/mescontacts.tpl       |   15 ++++++++++++++-
 templates/core/plset.tpl               |    2 +-
 templates/skin/common.title.header.tpl |    2 +-
 11 files changed, 55 insertions(+), 14 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1913 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
classes/plbacktrace.php
classes/plset.php
htdocs/css/default.css
htdocs/css/keynote.css
include/userset.inc.php
modules/carnet.php
modules/search/classes.inc.php
templates/carnet/mescontacts.tpl
templates/core/plset.tpl
templates/skin/common.title.header.tpl

index 3f33f58..a0a1856 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,9 @@ New:
 
 Bug/Wish:
 
+    * Carnet:
+        - #682: Can quick search in contact list                           -FRU
+
     * Core:
         - #674: MiniWiki xhtml validation                                  -FRU
         - #678: PlUpload filename detection                                -FRU
index 2f18f7a..e15a304 100644 (file)
@@ -39,7 +39,11 @@ class PlBacktrace
 
     private function fixCharset($action)
     {
-        return is_utf8($action) ? $action : utf8_encode($action);
+        if (!is_string($action)) {
+            return $action;
+        } else {
+            return is_utf8($action) ? $action : utf8_encode($action);
+        }
     }
 
     private function add(array &$entry, $sizef = 'rows', $timef = 'exectime', $errorf = 'error')
@@ -52,12 +56,12 @@ class PlBacktrace
         unset($entry[$timef]);
         $trace['rows'] = @$entry[$sizef];
         unset($entry[$sizef]);
-        $trace['error'] = @$entry[$errorf];
+        $trace['error'] = $this->fixCharset(@$entry[$errorf]);
         unset($entry[$errorf]);
         if ($trace['error']) {
             $this->error = true;
         }
-        $trace['data'] = array($entry);
+        $trace['data'] = array($this->fixCharset($entry));
         $this->traces[] =& $trace;
     }
 
@@ -90,7 +94,8 @@ class PlBacktrace
     {
         $trace =& $this->traces[count($this->traces) - 1];
         $trace['rows']  = $rows;
-        $trace['error'] = $error;
+        $trace['error'] = $this->fixCharset($error);
+        array_walk_recursive($userdata, array($this, 'fixCharset'));
         $trace['data']  = $userdata;
         if ($trace['error']) {
             $this->error = true;
index 576e864..8cf1ba2 100644 (file)
@@ -116,7 +116,6 @@ class PlSet
             $limitcount = "LIMIT $limitcount";
         }
         $joins  = $this->joins . ' ' . $joins;
-        $where  = $where;
         if (trim($this->where)) {
             if (trim($where)) {
                 $where .= ' AND ';
index 19d5ab2..2957cc6 100644 (file)
@@ -609,7 +609,7 @@ div.adresse strong {
     vertical-align: top;
 }
 
-#quick_search {
+.quick_search {
     color: gray;
     text-align: right;
 }
index ce1af92..415af9a 100644 (file)
@@ -625,7 +625,7 @@ div.adresse {
     font-size: 95%;
 }
 
-#quick_search {
+.quick_search {
     color: gray;
     background: #fff;
     text-align: right;
index a4e6dc7..7595292 100644 (file)
@@ -91,9 +91,20 @@ class SearchSet extends UserSet
             new ThrowError('Recherche trop générale.');
         }
         $this->score = $qSearch->get_score_statement();
-        parent::__construct($join . ' ' . $fields->get_select_statement(),
-                            $where . ' ' . $fields->get_where_statement() .
-                            (S::logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : ''));
+        $pwhere = $fields->get_where_statement();
+        if (trim($pwhere)) {
+            if (trim($where)) {
+                $where .= ' AND ';
+            }
+            $where .= $pwhere;
+        }
+        if (S::logged() && Env::has('nonins')) {
+            if (trim($where)) {
+                $where .= ' AND ';
+            }
+            $where .= 'u.perms="pending" AND u.deces=0';
+        }
+        parent::__construct($join . ' ' . $fields->get_select_statement(), $where);
 
         $this->order = implode(',',array_filter(array($fields->get_order_statement(),
                                                       'u.promo DESC, NomSortKey, prenom')));
index 108ebdb..9c9172b 100644 (file)
@@ -183,6 +183,12 @@ class CarnetModule extends PLModule
         return Array($total, $list);
     }
 
+    function searchErrorHandler($explain) {
+        global $page;
+        $page->trig($explain);
+        $this->handler_contacts($page);
+    }
+
     function handler_contacts(&$page, $action = null, $subaction = null, $ssaction = null)
     {
         $page->assign('xorg_title','Polytechnique.org - Mes contacts');
@@ -237,7 +243,10 @@ class CarnetModule extends PLModule
         if ($search && trim(Env::v('quick'))) {
             require_once 'userset.inc.php';
             $base = 'carnet/contacts/search';
-            $view = new SearchSet(true, false, "INNER JOIN contacts AS c2 ON (u.user_id = c2.contact)", " c2.uid = $uid AND ");
+
+            require_once(dirname(__FILE__) . '/search/classes.inc.php');
+            ThrowError::$throwHook = array($this, 'searchErrorHandler');
+            $view = new SearchSet(true, false, "INNER JOIN contacts AS c2 ON (u.user_id = c2.contact)", "c2.uid = $uid");
         } else {
             $base = 'carnet/contacts';
             $view = new UserSet("INNER JOIN contacts AS c2 ON (u.user_id = c2.contact)", " c2.uid = $uid ");
index 7664bb0..29d7163 100644 (file)
@@ -305,6 +305,7 @@ class QuickSearch extends SField
             $ip = XDB::escape($this->ip);
             $where[] = "( ls.ip = $ip OR ls.forward_ip = $ip )";
         }
+
         return join(" AND ", $where);
     }
 
index 870fe42..241e7b9 100644 (file)
@@ -39,7 +39,7 @@
   il te suffit de cliquer sur l'icône {icon name=add} en face de son nom dans les résultats !
 </p>  
 
-{if $plset_count}
+{if $plset_count || $smarty.request.quick}
 <p>
 Pour récupérer ta liste de contacts dans un PDF imprimable :<br />
 (attention, les photos font beaucoup grossir les fichiers !)
@@ -72,6 +72,19 @@ Pour récupérer ta liste de contacts dans un PDF imprimable :<br />
   </li>
 </ul>
 
+<p>
+  <div style="float: right">
+    <form action="carnet/contacts/search#plset_content" method="get">
+      <input type="text" size="30" name="quick" class="quick_search"
+             value="{$smarty.request.quick|default:'recherche dans tes contacts'}"
+             onfocus="if (this.value == 'recherche dans tes contacts') this.value=''"
+             onblur="if (this.value == '') this.value='recherche dans tes contacts'"/>
+      <a href="carnet/contacts">{icon name=cross title='Annuler la recherche'}</a>
+    </form>
+  </div>
+  Tu peux faire une recherche sur tes contacts :
+</p>
+
 {include file="core/plset.tpl"}
 
 {/if}
index 009aa23..511fbca 100644 (file)
@@ -20,7 +20,7 @@
 {*                                                                        *}
 {**************************************************************************}
 
-<div>
+<div style="clear: both">
 <h1 style="display: block; float: right">
   {if !$plset_count}
   Aucune entrée
index a4c73c4..fd4585d 100644 (file)
@@ -32,7 +32,7 @@
                 {insert name="getNbIns"} polytechniciens sur le web\r
                 <form action="search" method="get">\r
                     <div>\r
-                        <input type="text" size="30" name="quick" id="quick_search" value="{$smarty.request.quick|default:"recherche dans l'annuaire"}" onfocus="if (this.value == '{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}') this.value=''" onblur="if (this.value == '') this.value='{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}'"/>                        \r
+                        <input type="text" size="30" name="quick" class="quick_search" value="{$smarty.request.quick|default:"recherche dans l'annuaire"}" onfocus="if (this.value == '{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}') this.value=''" onblur="if (this.value == '') this.value='{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}'"/>                        \r
                     </div>\r
                 </form>\r
                 {insert name="getNbNotifs"}\r