From d1a2252ae9275f499f3a1d843f540ae5aeea63a9 Mon Sep 17 00:00:00 2001 From: Guillaume Bandet Date: Tue, 10 Jun 2008 11:43:56 +0200 Subject: [PATCH] Adds networking addresses in profile --- htdocs/javascript/profile.js | 53 +++++++++++++++++++++ include/user.func.inc.php | 12 +++++ modules/profile/general.inc.php | 79 ++++++++++++++++++++++++++++++++ templates/profile/general.networking.tpl | 46 +++++++++++++++++++ templates/profile/general.tpl | 25 +++++++--- templates/profile/profile.tpl | 13 +++++- upgrade/fusionax-0.0.1/02_networking.sql | 26 +++++++++++ 7 files changed, 246 insertions(+), 8 deletions(-) create mode 100644 templates/profile/general.networking.tpl create mode 100644 upgrade/fusionax-0.0.1/02_networking.sql diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 8a013ef..2b615e8 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -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 = '' + + ' ' + + ' ' + + ' ' + + ' site public' + + '  ' + + ' ' + + ' ' + + ' ' + text + '' + + ' ' + + text + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' cross' + + ' ' + + ' ' + + ''; + + 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) diff --git a/include/user.func.inc.php b/include/user.func.inc.php index c866ef9..c05aabb 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -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; } // }}} diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index a353492..87b1707 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -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 index 0000000..e7f7f28 --- /dev/null +++ b/templates/profile/general.networking.tpl @@ -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 *} +{* *} +{**************************************************************************} + + + + + + {icon name="flag_green" title="site public"} +   + + + {nw.name} + {$nw.name} + + + + + {icon name=cross title="Supprimer cet élément"} + + + + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index 5a7274f..1cbf27f 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -297,18 +297,29 @@ pour les premières lettres : Alfred de Musset" width + + Messageries, networking et sites web + + + - - - {icon name="flag_green" title="site public"} -   - Page web Perso + Type à ajouter - + + + {foreach from=$networking item=network key=id} + {include file="profile/general.networking.tpl" nw=$network i=$id} + {/foreach}
diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index 0694db3..405987f 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -50,6 +50,18 @@ function chgMainWinLoc(strPage) {if $x.gpxs_join}
Groupe{if count($x.gpxs) > 1}s{/if} et institution{if count($x.gpxs) > 1}s{/if} X :
{$x.gpxs_join|smarty:nodefaults}
{/if} {/if} + {if $x.networking} +

Messageries, networking et sites web :

+ {foreach from=$x.networking item=network} + {$network.name} + {if $network.filter == 'web'} + {$network.address} + {else} + {$network.address} + {/if} +
+ {/foreach} + {/if} {if $x.freetext}

Commentaires :

{$x.freetext|miniwiki|smarty:nodefaults} @@ -62,7 +74,6 @@ function chgMainWinLoc(strPage) {if $logged} {if $x.nickname} (alias {$x.nickname}){/if} {/if} - {if $x.web} {icon name="world_go" title="Site Web"}{/if} {if $logged}  {if !$x.dcd}{* *}{icon name=vcard title="Afficher la carte de visite"}{/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 index 0000000..cf368ff --- /dev/null +++ b/upgrade/fusionax-0.0.1/02_networking.sql @@ -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` <> ""; + -- 2.1.4