source: extensions/user_custom_fields/initprofile.php @ 32593

Last change on this file since 32593 was 32593, checked in by ddtddt, 3 years ago

[user_custom_fields] delete use ED tag in profil

File size: 3.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Custom Fields plugin for Piwigo by TEMMII                        |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2016-2021 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    }
47  $tab_user_register=tab_user_custom_fields_register();
48  $template->assign('UCF_USERNAME',$userdata['username']);
49  $template->assign('UCF_EMAIL',$userdata['email']);
50  while ($info_users = pwg_db_fetch_assoc($tab_user_register)) {
51       
52        $d=data_info_user($userdata['id'],$info_users['id_ucf']);
53        $row = pwg_db_fetch_assoc($d);
54        $items = array(
55                'UCFID' => $info_users['id_ucf'],
56                'UCFWORDING' => trigger_change('AP_render_content', $info_users['wording']),
57                'UCFOBLIGATORY' => $info_users['obligatory'],
58                'UCFDATA' => $row['data'],
59        );
60        $template->append('add_uers_register', $items);
61  }
62 }
63}
64
65 
66add_event_handler('save_profile_from_post', 'ucfPT2');
67function ucfPT2(){
68  global $prefixeTable,$userdata;
69  $profil_base_url = PHPWG_ROOT_PATH . '/profile.php';
70  foreach ($_POST['data'] AS $id_ucf => $data) {
71        $q = 'SELECT 1 FROM ' . UCFD_TABLE . ' WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
72        $test = pwg_query($q);
73        $row = pwg_db_fetch_assoc($test);
74        if (count($row) > 0){
75          if ($data != ''){
76                $query = 'UPDATE ' . UCFD_TABLE . ' SET data="' . $data . '" WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
77                pwg_query($query);
78          }else{
79                $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
80                pwg_query($query);
81          }
82        }else if ($data != ''){
83                $query = 'INSERT ' . UCFD_TABLE . '(id_user,id_ucf,data) VALUES (' . $userdata['id'] . ',' . $id_ucf . ',"' . $data . '");';
84                pwg_query($query);
85        }
86  }
87  redirect($profil_base_url); 
88}
89
90?>
Note: See TracBrowser for help on using the repository browser.