source: extensions/user_custom_fields/initprofile.php @ 31937

Last change on this file since 31937 was 31841, checked in by ddtddt, 7 years ago

[extensions] - user_custom_fields - Add import data plugin AddInfoUser

File size: 3.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Custom Fields plugin for Piwigo                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2016-2017 ddtddt               http://temmii.com/piwigo/ |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22//add prefiter
23add_event_handler('loc_begin_profile', 'ucfPI', 95 );
24
25function ucfPI(){
26  global $template;
27  $template->set_prefilter('profile_content', 'ucfPT');
28  $template->set_filename('ucf_profile_add', realpath(UCF_PATH.'ucf_profile_add.tpl'));
29  $template->assign_var_from_handle('UCF_PROFILE_ADD', 'ucf_profile_add');
30}
31
32function ucfPT($content, &$smarty){
33  $search = '/(<legend>{\'Registration).*({if \$ALLOW_USER_CUSTOMIZATION}
34  <fieldset>)/is';
35  return preg_replace($search, '{$UCF_PROFILE_ADD}'."\n".'{if $ALLOW_USER_CUSTOMIZATION}
36  <fieldset>', $content);
37 }
38
39add_event_handler('loc_begin_profile', 'ucfinitprofil');
40function ucfinitprofil(){
41  global $template, $prefixeTable, $userdata;
42 if (isset($userdata['id'])){ 
43  $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
44        if($PAED['state'] == 'active'){
45                add_event_handler('AP_render_content', 'get_user_language_desc');
46                $template->assign('useED',1);
47    }else{
48        $template->assign('useED',0);
49    }
50  $tab_user_register=tab_user_custom_fields_register();
51  $template->assign('UCF_USERNAME',$userdata['username']);
52  $template->assign('UCF_EMAIL',$userdata['email']);
53  while ($info_users = pwg_db_fetch_assoc($tab_user_register)) {
54       
55        $d=data_info_user($userdata['id'],$info_users['id_ucf']);
56        $row = pwg_db_fetch_assoc($d);
57        $items = array(
58                'UCFID' => $info_users['id_ucf'],
59                'UCFWORDING' => trigger_change('AP_render_content', $info_users['wording']),
60                'UCFOBLIGATORY' => $info_users['obligatory'],
61                'UCFDATA' => $row['data'],
62        );
63        $template->append('add_uers_register', $items);
64  }
65 }
66}
67
68 
69add_event_handler('save_profile_from_post', 'ucfPT2');
70function ucfPT2(){
71  global $prefixeTable,$userdata;
72  $profil_base_url = PHPWG_ROOT_PATH . '/profile.php';
73  foreach ($_POST['data'] AS $id_ucf => $data) {
74        $q = 'SELECT 1 FROM ' . UCFD_TABLE . ' WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
75        $test = pwg_query($q);
76        $row = pwg_db_fetch_assoc($test);
77        if (count($row) > 0){
78          if ($data != ''){
79                $query = 'UPDATE ' . UCFD_TABLE . ' SET data="' . $data . '" WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
80                pwg_query($query);
81          }else{
82                $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
83                pwg_query($query);
84          }
85        }else if ($data != ''){
86                $query = 'INSERT ' . UCFD_TABLE . '(id_user,id_ucf,data) VALUES (' . $userdata['id'] . ',' . $id_ucf . ',"' . $data . '");';
87                pwg_query($query);
88        }
89  }
90  redirect($profil_base_url); 
91}
92
93?>
Note: See TracBrowser for help on using the repository browser.