Adds networking addresses in profile
authorGuillaume Bandet <guillaume.bandet@polytechnique.org>
Tue, 10 Jun 2008 09:43:56 +0000 (11:43 +0200)
committerGuillaume Bandet <guillaume.bandet@polytechnique.org>
Tue, 10 Jun 2008 23:01:14 +0000 (01:01 +0200)
htdocs/javascript/profile.js
include/user.func.inc.php
modules/profile/general.inc.php
templates/profile/general.networking.tpl [new file with mode: 0644]
templates/profile/general.tpl
templates/profile/profile.tpl
upgrade/fusionax-0.0.1/02_networking.sql [new file with mode: 0644]

index 8a013ef..2b615e8 100644 (file)
@@ -110,6 +110,59 @@ function removeSearchName(i)
   }
 }
 
+function addNetworking()
+{
+    var i = 0;
+    var nw = 'networking_';
+    while (document.getElementById(nw + i) != null) {
+        i++;
+    }
+    var cb   = document.forms.prof_annu['nw_type'];
+    var id   = cb.value;
+    var text = cb.options[cb.selectedIndex].text;
+    var html = '<tr id="networking_' + i + '">'
+        + '  <td>'
+        + '    <span class="flags">'
+        + '      <input type="checkbox" name="networking[' + i + '][pub]"/>'
+        + '      <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
+        + '    </span>&nbsp;'
+        + '    <input type="hidden" name="networking[' + i + '][type]" value="' + id + '"/>'
+        + '    <input type="hidden" name="networking[' + i + '][name]" value="' + text + '"/>'
+        + '    <img src="profile/networking/' + id + '" alt="' + text + '" title="' + text + '" />'
+        + '    <span class="title">'
+        + text
+        + '    </span>'
+        + '  </td>'
+        + '  <td>'
+        + '    <input type="text" name="networking[' + i + '][address]" value="" size="30"/>'
+        + '    <a href="javascript:removeNetworking(' + i + ')">'
+        + '      <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
+        + '    </a>'
+        + '  </td>'
+        + '</tr>';
+
+    if (i == 0) {
+        $('#networking').after(html);
+    } else {
+        $('#networking_'+(i-1)).after(html);
+    }
+}
+
+function removeNetworking(id)
+{
+    $('#networking_' + id).remove();
+}
+
+function updateNetworking()
+{
+    var val = document.forms.prof_annu['nw_type'].value;
+    if (val == '') {
+        document.getElementById('nw_add').style.display = 'none';
+    } else {
+        document.getElementById('nw_add').style.display = '';
+    }
+}
+
 // Addresses
 
 function removeObject(id, pref)
index c866ef9..c05aabb 100644 (file)
@@ -500,6 +500,18 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
         }
     }
 
+    $user['networking'] = Array();
+    $res = XDB::iterator("SELECT  n.address, n.pub, m.network_type AS type, m.name, m.filter
+                            FROM  profile_networking AS n
+                      INNER JOIN  profile_networking_enum AS m ON (n.network_type = m.network_type)
+                           WHERE  n.uid = {?}", $uid);
+    while($network = $res->next())
+    {
+        if (has_user_right($network['pub'], $view)) {
+            $user['networking'][] = $network;
+        }
+    }
+
     return $user;
 }
 // }}}
index a353492..87b1707 100644 (file)
@@ -107,6 +107,79 @@ class ProfileAppli implements ProfileSetting
     }
 }
 
+class ProfileNetworking implements ProfileSetting
+{
+    private $email;
+    private $pub;
+    private $web;
+
+    public function __construct()
+    {
+        $this->email  = new ProfileEmail();
+        $this->pub    = new ProfilePub();
+        $this->web    = new ProfileWeb();
+    }
+
+    public function value(ProfilePage &$page, $field, $value, &$success)
+    {
+        if (is_null($value)) {
+            $value = array();
+            $res = XDB::iterator("SELECT  n.address, n.network_type AS type, n.pub, m.name
+                                    FROM  profile_networking AS n
+                              INNER JOIN  profile_networking_enum AS m ON (n.network_type = m.network_type)
+                                   WHERE  n.uid = {?}",
+                                 S::i('uid'));
+            while($network = $res->next()) {
+                $value[] = $network;
+            }
+        }
+        if (!is_array($value)) {
+            $value = array();
+        }
+        $res = XDB::iterator("SELECT filter, network_type AS type
+                                FROM profile_networking_enum;");
+        $filters = array();
+        while($filter = $res->next()) {
+            $filters[$filter['type']] = $filter['filter'];
+        }
+        $success = true;
+        foreach($value as $i=>&$network) {
+            if(!isset($network['pub'])) {
+                $network['pub'] = 'private';
+            }
+            $network['error'] = false;
+            $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s);
+            $s = true;
+            if ($filters[$network['type']] == 'web') {
+                $network['address'] = $this->web->value($page, 'address', $network['address'], $s);
+            } elseif ($filters[$network['type']] == 'email') {
+                $network['address'] = $this->email->value($page, 'address', $network['address'], $s);
+            }
+            if (!$s) {
+                $success = false;
+                $network['error'] = true;
+            }
+        }
+        return $value;
+    }
+
+    public function save(ProfilePage &$page, $field, $value)
+    {
+        XDB::execute("DELETE FROM profile_networking
+                            WHERE uid = {?}",
+                     S::i('uid'));
+        if (!count($value)) {
+            return;
+        }
+        $insert = array();
+        foreach ($value as $id=>$network) {
+            XDB::execute("INSERT INTO  profile_networking (uid, nwid, network_type, address, pub)
+                               VALUES  ({?}, {?}, {?}, {?}, {?})",
+                         S::i('uid'), $id, $network['type'], $network['address'], $network['pub']);
+        }
+    }
+}
+
 class ProfileGeneral extends ProfilePage
 {
     protected $pg_template = 'profile/general.tpl';
@@ -134,6 +207,7 @@ class ProfileGeneral extends ProfilePage
                                   = new ProfileBool();
         $this->settings['mobile'] = new ProfileTel();
         $this->settings['web'] = new ProfileWeb();
+        $this->settings['networking'] = new ProfileNetworking();
         $this->settings['appli1']
                                   = $this->settings['appli2']
                                   = new ProfileAppli();
@@ -245,6 +319,11 @@ class ProfileGeneral extends ProfilePage
     public function _prepare(PlatalPage &$page, $id)
     {
         require_once "applis.func.inc.php";
+
+        $res = XDB::iterator("SELECT nw.network_type AS type, nw.name
+                                FROM profile_networking_enum AS nw
+                            ORDER BY name");
+        $page->assign('network_list', $res->fetchAllAssoc());
     }
 }
 
diff --git a/templates/profile/general.networking.tpl b/templates/profile/general.networking.tpl
new file mode 100644 (file)
index 0000000..e7f7f28
--- /dev/null
@@ -0,0 +1,46 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2008 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<tr id="networking_{$i}">
+  <td>
+    <span class="flags">
+      <input type="checkbox"
+        {if $nw.pub neq 'private'} checked="checked"{/if}
+        name="networking[{$i}][pub]"/>
+      {icon name="flag_green" title="site public"}
+    </span>&nbsp;
+    <input type="hidden" name="networking[{$i}][type]" value="{$nw.type}"/>
+    <input type="hidden" name="networking[{$i}][name]" value="{$nw.name}"/>
+    <img src="profile/networking/{$nw.type}" alt="{nw.name}" title="{nw.name}" />
+    <span class="title">{$nw.name}</span>
+  </td>
+  <td>
+    <input type="text" name="networking[{$i}][address]" value="{$nw.address}"
+    {if $nw.error} class="error" {/if}
+    size="30"/>
+    <a href="javascript:removeNetworking({$i})">
+      {icon name=cross title="Supprimer cet élément"}
+    </a>
+  </td>
+</tr>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 5a7274f..1cbf27f 100644 (file)
@@ -297,18 +297,29 @@ pour les premières lettres : <strong>Alfred&nbsp;de&nbsp;Musset</strong>" width
     </td>
   </tr>
   <tr>
+    <td colspan="2">
+      <span class="titre">Messageries, networking et sites web</span>
+    </td>
+  </tr>
+  <tr id="networking">
     <td>
-      <span class="flags">
-        <input type="checkbox" name="web_pub" {if $web_pub eq 'public'}checked="checked"{/if} />
-        {icon name="flag_green" title="site public"}
-      </span>&nbsp;
-      <span class="titre">Page web Perso</span>
+      <span class="titre" style="margin-left:1em;">Type à ajouter</span>
     </td>
     <td>
-      <input type="text" size="35" maxlength="95" name="web"
-             {if $errors.web}class="error"{/if} value="{$web}" />
+      <select name="nw_type" onchange="updateNetworking()">
+        <option value=""></option>
+        {foreach from=$network_list item=network}
+          <option value="{$network.type}">{$network.name}</option>
+        {/foreach}
+      </select>
+      <span id="nw_add" style="display: none">
+        <a href="javascript:addNetworking();">{icon name=add title="Ajouter cette adresse"}</a>
+      </span>
     </td>
   </tr>
+  {foreach from=$networking item=network key=id}
+    {include file="profile/general.networking.tpl" nw=$network i=$id}
+  {/foreach}
   <tr class="pair">
     <td>
       <div>
index 0694db3..405987f 100644 (file)
@@ -50,6 +50,18 @@ function chgMainWinLoc(strPage)
       {if $x.gpxs_join}<div><em class="intitule">Groupe{if count($x.gpxs) > 1}s{/if} et institution{if count($x.gpxs) > 1}s{/if} X&nbsp;: </em>
       <span><br/>{$x.gpxs_join|smarty:nodefaults}</span></div>{/if}
     {/if}
+    {if $x.networking}
+      <h2>Messageries, networking et sites web&nbsp;:</h2>
+      {foreach from=$x.networking item=network}
+        <img style="width: auto; padding: 0" src="profile/networking/{$network.type}" alt="{$network.name}" title="{$network.name}"/>
+        {if $network.filter == 'web'}
+          <a href="{$network.address}">{$network.address}</a>
+        {else}
+          {$network.address}
+        {/if}
+        <br/>
+      {/foreach}
+    {/if}
     {if $x.freetext}
     <h2>Commentaires&nbsp;:</h2>
     <span>{$x.freetext|miniwiki|smarty:nodefaults}</span>
@@ -62,7 +74,6 @@ function chgMainWinLoc(strPage)
       {if $logged}
       {if $x.nickname} (alias {$x.nickname}){/if}
       {/if}
-      {if $x.web}&nbsp;<a href="{$x.web}">{icon name="world_go" title="Site Web"}</a>{/if}
       {if $logged}
       &nbsp;{if !$x.dcd}<a href="vcard/{$x.forlife}.vcf">{*
         *}{icon name=vcard title="Afficher la carte de visite"}</a>{/if}
diff --git a/upgrade/fusionax-0.0.1/02_networking.sql b/upgrade/fusionax-0.0.1/02_networking.sql
new file mode 100644 (file)
index 0000000..cf368ff
--- /dev/null
@@ -0,0 +1,26 @@
+CREATE TABLE IF NOT EXISTS `profile_networking_enum` (
+    `network_type` tinyint unsigned NOT NULL,
+    `name` varchar(30) NOT NULL,
+    `icon` varchar(50) NOT NULL COMMENT 'icon filename',
+    `filter` enum('email','web','none') NOT NULL DEFAULT 'none' COMMENT 'filter type for addresses',
+    PRIMARY KEY (`network_type`)
+) CHARSET=utf8 COMMENT='types of networking addresses';
+
+CREATE TABLE IF NOT EXISTS `profile_networking` (
+    `uid` smallint unsigned NOT NULL COMMENT 'user id',
+    `nwid` tinyint unsigned NOT NULL COMMENT 'number of the address for the user',
+    `network_type` tinyint unsigned NOT NULL,
+    `address` varchar(255) NOT NULL,
+    `pub` enum('private','public') NOT NULL DEFAULT 'private',
+    PRIMARY KEY (`uid`, `nwid`)
+) CHARSET=utf8 COMMENT='networking addresses';
+
+
+INSERT INTO `profile_networking_enum` (`network_type`, `name`, `icon`, `filter`)
+     VALUES (0, 'Page web', 'web.gif', 'web');
+
+INSERT INTO `profile_networking` (`uid`, `nwid`, `network_type`, `address`, `pub`)
+     SELECT `user_id`, 0, 0, `profile_web`, `profile_web_pub`
+       FROM `auth_user_quick`
+      WHERE `profile_web` <> "";
+