Changeset 19956
- Timestamp:
- Jan 7, 2013, 10:26:35 PM (12 years ago)
- Location:
- extensions/Piwecard
- Files:
-
- 3 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Piwecard/admin/admin_consult.php
r19926 r19956 12 12 13 13 if (isset($_GET['action'])) { 14 $action = $_GET['action']; 15 // delete one ecard 16 if ($action == "delete") { 17 $ecard_id = $_GET['id']; 18 $ecard->delete_ecard($ecard_id, isset($_GET['force'])); 19 redirect(ECARD_ADMIN . '-consult&start='.$start); 20 } elseif ($action == "delall") { // delete all unvalid 21 $ecard->delete_allinvalid_ecard(); 22 redirect(ECARD_ADMIN . '-consult'); 14 switch ($_GET['action']) { 15 case "delete" : 16 $ecard_id = $_GET['id']; 17 $ecard->delete_ecard($ecard_id); 18 redirect(ECARD_ADMIN . '-consult&start='.$start); 19 break; 20 case "delall" : 21 $ecard->delete_allinvalid_ecard(); 22 redirect(ECARD_ADMIN . '-consult'); 23 break; 24 default : 25 break; 23 26 } 24 } 27 } 28 25 29 26 30 //Create the navigation bar (for more than 1 page) … … 29 33 $ecard_navbar = create_navigation_bar($consult_url, $ecard->get_nb_ecard(), $start, $ecard->my_config['nb_ecard_page']); 30 34 31 $query = 'SELECT * FROM '.ECARD_TABLE.' ORDER BY date DESC LIMIT '.$start.','.$ecard->my_config['nb_ecard_page'].';';35 $query = 'SELECT * FROM '.ECARD_TABLE.' ORDER BY date_creation DESC LIMIT '.$start.','.$ecard->my_config['nb_ecard_page'].';'; 32 36 $result = pwg_query($query); 33 37 34 38 while($file = mysql_fetch_assoc($result)) { 35 $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$file[' numero']);39 $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$file['id']); 36 40 37 41 // Check if the ecard is valid 38 if ($ecard->is_valid($file['numero'])) 39 $actif = true; 40 else 41 $actif = false; 42 $valid = $ecard->is_valid($file['id']); 42 43 43 44 $template->append('ecard_file',array( 44 ' ID' => $file['numero'],45 ' SUJET' => $file['sujet'],46 ' LINK' => $ecard_url,47 ' FROM' => $file['nomexp'],48 ' FROMMAIL' => $file['adrexp'],49 ' TO' => $file['nomdest'],50 ' TOMAIL' => $file['adrdest'],51 ' DATE' => $file['date'],52 ' VALID' => $actif,53 ' ECARD_DELETE' => $consult_url.'&action=delete&id='.$file['numero'].'&start='.$start,54 ' ECARD_DELETE_ADM' => $consult_url.'&action=delete&id='.$file['numero'].'&force&start='.$start,45 'id' => $file['id'], 46 'subject' => $file['subject'], 47 'url' => $ecard_url, 48 'sender_name' => $file['sender_name'], 49 'sender_email' => $file['sender_email'], 50 'recipient_name' => $file['recipient_name'], 51 'recipient_email' => $file['recipient_email'], 52 'date_creation' => strftime('%d/%m/%y %H:%M', strtotime($file['date_creation'])), 53 'date_validity' => (isset($file['date_validity'])) ? strftime('%d/%m/%y %H:%M', strtotime($file['date_validity'])) : l10n('ecard_nolimit'), 54 'valid' => $valid, 55 'delete' => $consult_url.'&action=delete&id='.$file['id'].'&start='.$start, 55 56 )); 56 57 } 57 58 58 59 // Get the number of ecard (total & valid & invalid) 59 $template->assign(' NBECARDVALID', $ecard->get_nb_valid_ecard());60 $template->assign(' NBECARD', $ecard->get_nb_ecard());60 $template->assign('nb_ecard_valid', $ecard->get_nb_valid_ecard()); 61 $template->assign('nb_ecard', $ecard->get_nb_ecard()); 61 62 62 63 $template->assign('ecard_del_all', $consult_url.'&action=delall' ); -
extensions/Piwecard/admin/admin_manage.php
r19926 r19956 150 150 $template->assign(Array( 151 151 'F_ACTION' => '', 152 'L_CAT_OPTIONS_TRUE' => l10n(' SelectedCat'),153 'L_CAT_OPTIONS_FALSE' => l10n(' NonSelectedCat'),152 'L_CAT_OPTIONS_TRUE' => l10n('To Translate!'), 153 'L_CAT_OPTIONS_FALSE' => l10n('To Translate!'), 154 154 )); 155 155 -
extensions/Piwecard/admin/template/admin_consult.tpl
r19926 r19956 6 6 <div id="ECardAdminConsult"> 7 7 <div class="ecard_first_line"> 8 {'ecard_list'|@translate} [{$ NBECARDVALID} {'valid'|@translate} / {$NBECARD} {'total'|@translate}]8 {'ecard_list'|@translate} [{$nb_ecard_valid} {'valid'|@translate} / {$nb_ecard} {'total'|@translate}] 9 9 <a href="{$ecard_del_all}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');" title="{'ecard_delete_all'|@translate}"> 10 10 {'ecard_delete_all'|@translate} … … 13 13 </div> 14 14 {if count($ecard_file)} 15 {foreach from=$ecard_file item=ecard_file} 16 <div class="ecard_list"> 17 <span> 18 <a href="{$ecard_file.ECARD_DELETE_ADM}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');" title="{'ecard_force_delete'|@translate}"><img src="{$themeconf.admin_icon_dir}/delete.png" alt="{'ecard_force_delete'|@translate}"/></a> 19 </span> 20 <span> 21 {if $ecard_file.VALID} 22 <img src="{$themeconf.admin_icon_dir}/validate_s.png" alt="{'ecard_valid'|@translate}"/> 23 {else} 24 <a href="{$ecard_file.ECARD_DELETE}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');" title="{'ecard_delete'|@translate}"><img src="{$themeconf.admin_icon_dir}/uncheck.png" alt="{'ecard_invalid'|@translate}"/></a> 15 <table class="table2" width="97%"> 16 <thead> 17 <tr class="throw"> 18 <td> </td> 19 <td>col1</td> 20 <td>col2</td> 21 <td>col3</td> 22 <td>col4</td> 23 <td>col5</td> 24 <td>col6</td> 25 </tr> 26 </thead> 27 <tbody> 28 {foreach from=$ecard_file item=ecard_file name=foreach_ecard_file} 29 {if $smarty.foreach.foreach_ecard_file.iteration is even} 30 <tr class="row1"> 31 {else} 32 <tr class="row2"> 25 33 {/if} 26 </span> 27 <span> 28 {$ecard_file.DATE} 29 </span> 30 <span> 31 <a href="{$ecard_file.LINK}">{$ecard_file.SUJET}</a> 32 </span> 33 <span> 34 {'ecard_from'|@translate} {$ecard_file.FROM} ({$ecard_file.FROMMAIL}) {'ecard_to'|@translate} {$ecard_file.TO} ({$ecard_file.TOMAIL}) 35 </span> 36 </div> 37 {/foreach} 34 <td> 35 <input type="checkbox" name="selection[]" value="1"> 36 </td> 37 <td> 38 {$ecard_file.date_creation} 39 </td> 40 <td> 41 <a href="{$ecard_file.url}">{$ecard_file.subject}</a> 42 </td> 43 <td> 44 {$ecard_file.sender_name} ({$ecard_file.sender_email}) 45 </td> 46 <td> 47 {$ecard_file.recipient_name} ({$ecard_file.recipient_email}) 48 </td> 49 <td> 50 {$ecard_file.date_validity} 51 {if $ecard_file.valid} 52 <img src="{$themeconf.admin_icon_dir}/validate_s.png" alt="{'ecard_valid'|@translate}"/> 53 {else} 54 <img src="{$themeconf.admin_icon_dir}/infos.png" alt="{'ecard_invalid'|@translate}" height="16px"/> 55 {/if} 56 </td> 57 <td> 58 <a href="{$ecard_file.delete}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');" title="{'ecard_force_delete'|@translate}"><img src="{$themeconf.admin_icon_dir}/delete.png" alt="{'ecard_force_delete'|@translate}" height="16px"/></a> 59 </td> 60 </tr> 61 {/foreach} 62 </tbody> 63 </table> 38 64 {else} 39 65 <div class="ecard_no_ecard"> 40 {'ecard_no_ card'|@translate}66 {'ecard_no_ecard'|@translate} 41 67 </div> 42 68 {/if} -
extensions/Piwecard/include/config_param.inc.php
r19925 r19956 15 15 '%ecardmessage%' => isset($_POST['ecard_message']) ? $_POST['ecard_message'] : '' , 16 16 '%pictureurl%' => DerivativeImage::thumb_url($image_element) , 17 '%pictureinfos%' => isset($image_element['picture_infos']) ? $image_element['picture_infos'] : '' ,17 '%pictureinfos%' => isset($image_element['picture_infos']) ? $image_element['picture_infos'] : '' , 18 18 ); 19 19 -
extensions/Piwecard/include/ecard.class.php
r19924 r19956 1 1 <?php 2 /*3 * Plugin Name: Piwecard4 * File : ecard.php5 */6 7 2 global $user, $conf; 8 3 9 4 class ecard { 10 var $debug = false; 11 var $my_config ; 12 var $infos = array(); // contains all the info of the ecard : message, subject.... 5 var $my_config; 13 6 var $user_groups = array(); 14 7 15 8 // Class constructor 16 function ecard() {9 function __construct() { 17 10 $this->load_config(); 18 11 } 19 20 12 21 13 // Load general configuration from config_database 22 14 function load_config() { 23 $query = ' 24 SELECT value 25 FROM '.CONFIG_TABLE.' 26 WHERE param = \'ecard\' 27 ;'; 28 15 $query = 'SELECT value FROM '.CONFIG_TABLE.' WHERE param="piwecard";'; 29 16 $result = pwg_query($query); 30 17 … … 48 35 49 36 // Save general configuration to config_database 50 function save_config() 51 { 52 $query = ' 53 REPLACE INTO '.CONFIG_TABLE.' 54 VALUES( 55 \'ecard\', 56 \''.serialize($this->my_config).'\', 57 \'Configuration ecard\') 58 ;'; 59 37 function save_config() { 38 $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.serialize($this->my_config).'" WHERE param="piwecard";'; 60 39 $result = pwg_query($query); 61 40 … … 71 50 global $user; 72 51 73 $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id =' . $user['id'] . ';';52 $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id=' . $user['id'] . ';'; 74 53 75 54 $result = pwg_query($query); … … 107 86 108 87 // NB of days between 2 dates "AAAA-MM-JJ HH:hh:ss" 109 function NbJours($debut, $fin) {88 /* function NbJours($debut, $fin) { 110 89 $tDeb = explode("-", substr($debut,0,strpos($debut, ' '))); 111 90 $tFin = explode("-", substr($fin,0,strpos($fin, ' '))); … … 131 110 132 111 return($tFin); 133 } 112 } */ 134 113 135 114 function parse($data, $_POST = NULL, $image_element = NULL) { … … 138 117 $patterns = array(); 139 118 $replacements = array(); 140 foreach ($ecard_parse as $key => $value) 141 { 119 foreach ($ecard_parse as $key => $value) { 142 120 array_push($patterns, $key); 143 121 array_push($replacements, $value); … … 149 127 // Get the number of ecard in the database 150 128 function get_nb_ecard() { 151 $query = 'SELECT COUNT(DISTINCT numero) as nb FROM '.ECARD_TABLE 152 . ' ORDER BY date' 153 .';'; 129 $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' ORDER BY date_creation;'; 154 130 $result = pwg_query($query); 131 155 132 if ($result) { 156 133 $nb=mysql_fetch_assoc($result); 157 134 return $nb['nb']; 158 } 159 else 135 } else 160 136 return 0; 161 137 } … … 163 139 // Get the number of valid ecard in the database 164 140 function get_nb_valid_ecard() { 165 $query = 'SELECT numero,date,duration FROM '.ECARD_TABLE 166 .';'; 141 $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();'; 167 142 $result = pwg_query($query); 168 $count = 0;169 while($ecard_info = mysql_fetch_assoc($result)) {170 if ($ecard_info['duration'] == 0 OR $this->NbJours($ecard_info['date'], date("Y-m-d H:m:s")) <= $ecard_info['duration']) // activ ecard171 $count++;172 } 173 return $count;143 144 if ($result) { 145 $nb=mysql_fetch_assoc($result); 146 return $nb['nb']; 147 } else 148 return 0; 174 149 } 175 150 … … 178 153 function get_ecard($ecard_id = null) { 179 154 if ($ecard_id!== null) { 180 $query = ' 181 SELECT * 182 FROM ' . ECARD_TABLE .' 183 WHERE numero ="' . $ecard_id . '" 184 LIMIT 1 185 '; 155 $query = 'SELECT * FROM ' . ECARD_TABLE .' WHERE id ="' . $ecard_id . '" LIMIT 1;'; 186 156 187 157 $result = pwg_query($query); … … 191 161 return false; 192 162 } 193 194 } 195 196 // Get ecard information into array 197 function is_valid($ecard_id = null, $param_date=false) { 198 if ($ecard_id!== null) { 163 } 164 165 function is_valid($ecard_id = null) { 166 if (isset($ecard_id)) { 199 167 $ecard_info = $this->get_ecard($ecard_id); 200 if ($ecard_info != false) 201 { 202 168 if (isset($ecard_info)) { 203 169 // Valid duration for an ecard 204 $duration = ($param_date ? $this->my_config['activ'] : $ecard_info['duration']); 205 if ($this->debug) 206 { 207 foreach ($ecard_info as $i=>$v) 208 echo "ecard[".$i."]=".$v." \ "; 209 echo "NBjours = ".$this->NbJours($ecard_info['date'], date("Y-m-d H:m:s"))." -"; 210 echo "Activenb=".$this->my_config['activ']." -"; 211 } 170 $date_validity = $ecard_info['date_validity']; 212 171 213 214 if (isset ($ecard_info)215 AND $duration != 0 // 0 means always activ216 AND ($this->NbJours($ecard_info['date'], date("Y-m-d H:m:s")) > $duration) // Inactiv ecard217 )218 {219 return false;172 if (isset($date_validity)) { 173 $now = new DateTime(date("Y-m-d H:i:s")); 174 $date_validity = new DateTime($date_validity); 175 if ($date_validity > $now) 176 return true; 177 else 178 return false; 220 179 } else { 221 180 return true; 222 181 } 223 } 224 else 182 } else 225 183 return false; 226 184 } else { 227 return true; 228 } 229 } 230 185 return false; 186 } 187 } 231 188 232 189 // delete one ecard 233 190 // force to delete valid ecard 234 function delete_ecard($ecard_id = null, $force = false) { 235 if ($ecard_id!== null) { 236 $ecard_info = $this->get_ecard($ecard_id); 237 if ($this->debug) 238 { 239 foreach ($ecard_info as $i=>$v) 240 echo "ecard[".$i."]=".$v." \ "; 241 } 242 if (isset ($ecard_info) 243 and ( ($this->NbJours($ecard_info['date'], date("Y-m-d H:m:s")) > $this->my_config['activ']) // Inactiv ecard 244 OR $force // Or force to delete even if activ 245 ) 246 ) 247 248 $query = ' 249 DELETE 250 FROM ' . ECARD_TABLE .' 251 WHERE numero ="' . $ecard_id . '" 252 '; 191 function delete_ecard($ecard_id = null) { 192 if (isset($ecard_id)) { 193 $query = 'DELETE FROM ' . ECARD_TABLE .' WHERE id="' . $ecard_id . '";'; 253 194 pwg_query($query); 254 } 255 else 195 } else 256 196 return false; 257 197 } … … 259 199 // Delete all invalid ecard 260 200 function delete_allinvalid_ecard() { 261 $date = $this->AjoutJours(date("Y-m-d H:m:s"), $this->my_config['activ'], true); 262 263 $query = ' 264 DELETE 265 FROM ' . ECARD_TABLE .' 266 WHERE date < "' . $date . '" 267 '; 268 201 $query = 'DELETE FROM ' . ECARD_TABLE .' WHERE date_validity < NOW();'; 269 202 pwg_query($query); 270 271 203 } 272 204 … … 324 256 325 257 // author of the photo 326 $authorname = ""; 327 $query = ' 328 SELECT author 329 FROM '.IMAGES_TABLE.' 330 WHERE id = '.$page['image_id'] 331 .' LIMIT 1' 332 .';'; 258 $query = 'SELECT author FROM '.IMAGES_TABLE.' WHERE id = '.$page['image_id'].' LIMIT 1;'; 333 259 $result = pwg_query($query); 334 260 if (isset($result)) { … … 367 293 // Template informations 368 294 $template->assign('ecard', array( 369 'subject' 370 'message' => l10n('ecard_send_message'),371 'sender_name' => $user['username'],372 'sender_email' => $user['email'],373 'recipient_name' 374 'recipient_email' => l10n('ecard_send_dest_mail'),375 'copy' => $this->my_config['send_copy'] ? 'checked="checked"' : '',376 'changemail' => ($this->my_config['expmail_change'] ? '' : 'disabled="disabled"')295 'subject' => l10n('ecard_send_title'), 296 'message' => l10n('ecard_send_message'), 297 'sender_name' => $user['username'], 298 'sender_email' => $user['email'], 299 'recipient_name' => l10n('ecard_send_dest_name'), 300 'recipient_email' => l10n('ecard_send_dest_mail'), 301 'copy' => $this->my_config['send_copy'] ? 'checked="checked"' : '', 302 'changemail' => ($this->my_config['expmail_change'] ? '' : 'disabled="disabled"') 377 303 )); 378 304 … … 421 347 422 348 $insert = array( 423 'numero' => $image_element['next_element_id'], 424 'nomexp' => $_POST['ecard_sender_name'], 425 'nomdest' => $_POST['ecard_recipient_name'], 426 'adrexp' => $_POST['ecard_sender_email'], 427 'adrdest' => $_POST['ecard_recipient_email'], 428 'sujet' => $_POST['ecard_subject'], 429 'message' => $_POST['ecard_message'], 430 'image' => $image_element['id'], 431 'date' => date("Y-m-d H:i:s"), 432 'duration' => (isset($_POST['ecard_validity']) ? $_POST['ecard_validity'] : $this->my_config['activ']), 349 'id' => $image_element['next_element_id'], 350 'sender_name' => $_POST['ecard_sender_name'], 351 'recipient_name' => $_POST['ecard_recipient_name'], 352 'sender_email' => $_POST['ecard_sender_email'], 353 'recipient_email' => $_POST['ecard_recipient_email'], 354 'subject' => $_POST['ecard_subject'], 355 'message' => $_POST['ecard_message'], 356 'image' => $image_element['id'], 357 'date_creation' => date("Y-m-d H:i:s"), 433 358 ); 434 // TO DO : add valid date (end date or duration) / add number (increment number) / 359 if ($_POST['ecard_validity'] != '0') { 360 $date = new DateTime(); 361 $date->modify("+".$_POST['ecard_validity']." day"); 362 $insert['date_validity'] = $date->format('Y-m-d H:i:s'); 363 } 435 364 single_insert(ECARD_TABLE, $insert); 436 365 -
extensions/Piwecard/main.inc.php
r19926 r19956 26 26 define('ECARD_IMG_PATH' , PHPWG_PLUGINS_PATH . ECARD_DIR . '/img/'); 27 27 define('ECARD_ADMIN_PATH' , PHPWG_PLUGINS_PATH . ECARD_DIR . '/admin/'); 28 define('ECARD_TABLE' , $prefixeTable . ' ecard');28 define('ECARD_TABLE' , $prefixeTable . 'piwecard'); 29 29 define('ECARD_ADMIN', get_root_url() . 'admin.php?page=plugin-'.ECARD_DIR); 30 30 -
extensions/Piwecard/maintain.inc.php
r19925 r19956 1 1 <?php 2 /*3 * Plugin Name: Piwecard4 * File : maintain.inc.php5 */6 7 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 8 3 9 4 function plugin_install() { 10 global $prefixeTable , $conf;5 global $prefixeTable; 11 6 12 $query = 'SHOW TABLES LIKE "' . $prefixeTable . 'ecard"'; 7 require_once('install/functions.inc.php'); 8 9 $query = 'SHOW TABLES LIKE "'.$prefixeTable.'piwecard"'; 13 10 $result = pwg_query($query); 14 if (!mysql_fetch_row($result)) { 15 16 // ecard description 17 $q = 'CREATE TABLE `' . $prefixeTable . 'ecard` ( 18 `numero` CHAR(64) not null, 19 `nomexp` CHAR(100) not null, 20 `nomdest` CHAR(100) not null, 21 `adrexp` CHAR(100) not null, 22 `adrdest` CHAR(100) not null, 23 `sujet` CHAR(100) not null, 24 `message` TEXT not null, 25 `image` smallint(5) not null, 26 `date` datetime NOT NULL, 27 `duration` smallint(5) not null default 10, 28 PRIMARY KEY (`numero`), 29 UNIQUE (`numero`) 30 ) DEFAULT CHARSET=utf8;'; 31 pwg_query($q); 32 33 $q = ' 34 INSERT INTO '.CONFIG_TABLE.' (param,value,comment) 35 VALUES ("ecard","","Configuration ecard") 36 ;'; 37 38 pwg_query($q); 11 if (!pwg_db_fetch_row($result)) { 12 piwecard_db_create($prefixeTable.'piwecard'); 13 piwecard_conf_create('piwecard'); 39 14 } 40 15 } 41 16 42 17 function plugin_activate() { 43 18 global $prefixeTable; 19 20 require_once('install/functions.inc.php'); 21 22 $query_ecard = 'SHOW TABLES LIKE "'.$prefixeTable.'ecard"'; 23 $result_ecard = pwg_query($query_ecard); 24 $query_piwecard = 'SHOW TABLES LIKE "'.$prefixeTable.'piwecard"'; 25 $result_piwecard = pwg_query($query_piwecard); 26 if (pwg_db_num_rows($result_ecard) != 0) { //Update old configs 27 if (pwg_db_num_rows($result_piwecard) == 0){ 28 piwecard_db_create($prefixeTable.'piwecard'); 29 piwecard_db_populate($prefixeTable.'ecard', $prefixeTable.'piwecard'); 30 } 31 piwecard_db_delete($prefixeTable.'ecard'); 32 33 piwecard_conf_rename('ecard', 'piwecard'); 34 } 44 35 } 45 36 46 37 function plugin_uninstall() { 47 38 global $prefixeTable; 48 39 49 $q = 'DROP TABLE ' . $prefixeTable . 'ecard;'; 50 pwg_query($q); 51 52 $q = ' 53 DELETE FROM '.CONFIG_TABLE.' 54 WHERE param="ecard" LIMIT 1 55 ;'; 56 pwg_query($q); 40 require_once('install/functions.inc.php'); 41 42 piwecard_db_delete($prefixeTable.'piwecard'); 43 piwecard_conf_delete('piwecard'); 57 44 } 58 45 ?>
Note: See TracChangeset
for help on using the changeset viewer.