Changeset 551
- Timestamp:
- 04/18/05 01:19:16 (8 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 9 modified
-
ChangeLog (modified) (1 diff)
-
wifidog/admin/content_admin.php (modified) (5 diffs)
-
wifidog/classes/AbstractDbPostgres.php (modified) (17 diffs)
-
wifidog/classes/Content.php (modified) (22 diffs)
-
wifidog/classes/Content/ContentGroup.php (modified) (2 diffs)
-
wifidog/classes/Content/ContentGroupElement.php (modified) (7 diffs)
-
wifidog/classes/Content/Langstring.php (modified) (3 diffs)
-
wifidog/classes/LocaleList.php (modified) (5 diffs)
-
wifidog/classes/User.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/ChangeLog
r550 r551 1 2005-04-18 Benoit Grégoire <bock@step.polymtl.ca> 2 * Much more complete admin, initial access control work. 3 1 4 2005-04-15 Benoit Grégoire <bock@step.polymtl.ca> 2 5 * Support more of the content object model, do a half-decent CSS for the admin interface. -
trunk/wifidog-auth/wifidog/admin/content_admin.php
r550 r551 1 1 <?php 2 2 3 /********************************************************************\ 3 4 * This program is free software; you can redistribute it and/or * … … 25 26 define('BASEPATH', '../'); 26 27 require_once 'admin_common.php'; 27 define ('CONTENT_ADMIN_HREF', 'content_admin.php');28 define('CONTENT_ADMIN_HREF', 'content_admin.php'); 28 29 require_once BASEPATH.'classes/Content.php'; 29 30 require_once BASEPATH.'classes/Style.php'; … … 34 35 if (empty ($_REQUEST['action'])) 35 36 { 36 $_REQUEST['action'] ='list_all_content';37 $_REQUEST['action'] = 'list_all_content'; 37 38 } 38 39 39 40 if ($_REQUEST['action'] == 'list_all_content') 40 41 { 41 $sql = "SELECT * FROM content ";42 $sql = "SELECT * FROM content WHERE is_persistent=TRUE"; 42 43 $db->ExecSql($sql, $results, false); 43 if ($results!=null)44 if ($results != null) 44 45 { 45 echo "<table>\n"; 46 echo "<tr><th>"._("Title")."</th><th>"._("Content type")."</th><th>"._("Description")."</th></tr>\n"; 47 48 foreach ($results as $row) 49 { 50 if(!empty($row['title'])) 46 echo "<table>\n"; 47 echo "<tr><th>"._("Title")."</th><th>"._("Content type")."</th><th>"._("Description")."</th></tr>\n"; 48 49 foreach ($results as $row) 51 50 { 52 $title = Content::getContent($row['title']); 53 $title_ui = $title->getUserUI(); 51 $content=Content :: getContent($row['content_id']); 52 if (!empty ($row['title'])) 53 { 54 $title = Content :: getContent($row['title']); 55 $title_ui = $title->getUserUI(); 56 } 57 else 58 { 59 $title_ui = null; 60 } 61 62 if (!empty ($row['description'])) 63 { 64 $description = Content :: getContent($row['description']); 65 $description_ui = $description->getUserUI(); 66 } 67 else 68 { 69 $description_ui = null; 70 } 71 $href = "?content_id=$row[content_id]&action=edit"; 72 echo "<tr><td>$title_ui</td><td><a href='$href'>$row[content_type]</a></td><td>$description_ui</td>\n"; 73 $href = "?content_id=$row[content_id]&action=delete"; 74 if($content->isOwner(User::getCurrentUser())) 75 echo "<td><a href='$href'>Delete</a></td>"; 76 echo "</tr>\n"; 77 54 78 } 55 else 56 { 57 $title_ui =null; 58 } 59 60 if(!empty($row['description'])) 61 { 62 $description = Content::getContent($row['description']); 63 $description_ui = $description->getUserUI(); 64 } 65 else 66 { 67 $description_ui =null; 68 } 69 $href = "?content_id=$row[content_id]&action=edit"; 70 echo "<tr><td>$title_ui</td><td><a href='$href'>$row[content_type]</a></td><td>$description_ui</td></tr>\n"; 71 72 } 73 echo "</table>\n"; 79 echo "</table>\n"; 74 80 } 75 81 else … … 82 88 $html .= '</form>'; 83 89 } 84 if ($_REQUEST['action'] == 'save') 90 if ($_REQUEST['action'] == 'save') 91 { 92 $content = Content :: getContent($_REQUEST['content_id']); 93 $html .= $content->processAdminUI(); 94 $_REQUEST['action'] = 'edit'; 95 } 96 97 if ($_REQUEST['action'] == 'edit') 98 { 99 if (!empty ($_REQUEST['new_submit'])) 85 100 { 86 $content = Content :: getContent($_REQUEST['content_id']); 87 $html .= $content->processAdminUI(); 88 $_REQUEST['action'] = 'edit'; 101 $content = Content :: createNewContent(); 102 $content->setIsPersistent(true); 89 103 } 90 91 92 if ($_REQUEST['action'] == 'edit') 104 else 93 105 { 94 if (!empty ($_REQUEST['new_submit'])) 95 { 96 $content = Content :: createNewContent(); 97 } 98 else 99 { 100 $content = Content :: getContent($_REQUEST['content_id']); 101 } 106 $content = Content :: getContent($_REQUEST['content_id']); 107 } 102 108 $html .= "<form action='".CONTENT_ADMIN_HREF."' method='post'>"; 103 109 $html .= "<input type='hidden' name='content_id' value='".$content->GetId()."'>\n"; … … 106 112 $html .= "<input type=submit name='save_submit' value='"._("Save")."'>\n"; 107 113 $html .= '</form>'; 114 } 108 115 109 } 110 111 if(false) 112 { 113 if ($user == null) 114 { 115 echo "<H1>Erreur, l'usager ".$_REQUEST['user_admin_username_orig']." est introuvable</H1>\n"; 116 } 117 else 118 { 119 if (!empty ($_REQUEST['action']) && $_REQUEST['action'] == 'save') 120 { 121 $user->TraiterInterfaceAdmin(); 122 } 116 if ($_REQUEST['action'] == 'delete') 117 { 123 118 124 if ($_REQUEST['action'] == 'save' && !empty ($_REQUEST['delete_action']) && !empty ($_REQUEST['delete_confirm']) && $_REQUEST['delete_confirm'] == 'true') 125 { 126 echo "<H1>Je tente d'effacer la l'administrateur</H1>\n"; 127 $user->Delete(); 128 echo "<H1>Terminé, si vous ne voyez rien plus haut, c'est que l'administrateur a été effacée avec succès.</H1>\n"; 129 } 130 else 131 { 132 echo '<form action="" method="get">'; 133 $user->AfficherInterfaceAdmin(); 134 echo "<input type='hidden' name='action' value='save'>\n"; 135 echo "<input type='hidden' name='user_admin_username_orig' value='".$user->GetId()."'>\n"; 136 echo "<input type=submit name='save_action' value='Enregistrer'>\n"; 137 echo "<input type=submit name='delete_action' value='Effacer'><input type='checkbox' name='delete_confirm' value='true'>Oui, je suis certain.\n"; 119 $content = Content :: getContent($_REQUEST['content_id']); 120 $content->delete(); 121 $html .= "Content deleted"; 122 } 138 123 139 echo '</form>'; 140 } 141 } 142 143 } 144 echo $html; 145 $smarty->display("templates/footer.html"); 124 echo $html; 125 $smarty->display("templates/footer.html"); 146 126 ?> 147 127 128 -
trunk/wifidog-auth/wifidog/classes/AbstractDbPostgres.php
r545 r551 23 23 */ 24 24 error_reporting(E_ALL); 25 /** Classe statique, permet d'abstraire la connexion � la base de donn�e25 /** Classe statique, permet d'abstraire la connexion à la base de donnée 26 26 */ 27 27 class AbstractDb … … 46 46 } 47 47 48 /**Ex �cute la requ�te, et retourne le r�sultat. Affiche l'erreur s'il y a lieu.49 @param $sql Requ�te SELECT � ex�cuter50 @param $returnResults un array � deux dimensions des rang�es de r�sultats, NULL si aucun r�sultats.51 @param $debug Si TRUE, affiche les r �sultats bruts de la requ�te52 @return TRUE si la requete a �t� effectu�e avec succ�s, FALSE autrement.48 /**Exécute la requête, et retourne le résultat. Affiche l'erreur s'il y a lieu. 49 @param $sql requête SELECT à exécuter 50 @param $returnResults un array à deux dimensions des rangées de résultats, NULL si aucun résultats. 51 @param $debug Si TRUE, affiche les résultats bruts de la requête 52 @return TRUE si la requete a été effectuée avec succés, FALSE autrement. 53 53 */ 54 54 function ExecSql($sql, & $returnResults, $debug=false) … … 57 57 if ($debug == TRUE) 58 58 { 59 echo "<hr /><p>ExecuterSql(): DEBUG: Requ �te:<br>\n<pre>$sql</pre></p>\n<p>Plan:<br />\n";59 echo "<hr /><p>ExecuterSql(): DEBUG: Requête:<br>\n<pre>$sql</pre></p>\n<p>Plan:<br />\n"; 60 60 $result = pg_query($connection, "EXPLAIN ".$sql); 61 61 … … 89 89 if ($debug == TRUE) 90 90 { 91 echo "<P>Temps �coul� pour la requ�te SQL: $sql_timetaken seconde(s)</P>\n";91 echo "<P>Temps écoulé pour la requête SQL: $sql_timetaken seconde(s)</P>\n"; 92 92 } 93 93 94 94 if ($result == FALSE) 95 95 { 96 echo "<p>ExecuterSql(): ERREUR: Lors de l'ex �cution de la requ�te SQL:<br>$sql</p>";96 echo "<p>ExecuterSql(): ERREUR: Lors de l'exécution de la requête SQL:<br>$sql</p>"; 97 97 echo "<p>L'erreur est:<br>".pg_last_error($connection)."</p>"; 98 98 $returnResults = NULL; … … 112 112 { 113 113 $num_rows = pg_num_rows($result); 114 echo "<p>ExecuterSql(): DEBUG: Il y a $num_rows r �sultats:<br><TABLE class='spreadsheet'>";114 echo "<p>ExecuterSql(): DEBUG: Il y a $num_rows résultats:<br><TABLE class='spreadsheet'>"; 115 115 if ($returnResults != NULL) 116 116 { 117 //On affiche l'en-t �te des colonnes une seule fois*/117 //On affiche l'en-téte des colonnes une seule fois*/ 118 118 echo "<TR class='spreadsheet'>"; 119 119 while (list ($col_name, $col_content) = each($returnResults[0])) … … 139 139 } 140 140 141 /**Retourne une chaine de caract �re dans un format compatible pour stockage dans la bd142 @param $chaine La cha �ne de caract�re �nettoyer143 @return La cha �ne nettoy�e141 /**Retourne une chaine de caractère dans un format compatible pour stockage dans la bd 142 @param $chaine La chaéne de caractère à nettoyer 143 @return La chaéne nettoyée 144 144 */ 145 145 function EscapeString($chaine) … … 155 155 } 156 156 157 /** Nettoye une chaine de caract �re dans un format compatible bytea.158 @param $chaine La cha �ne de caract�re �nettoyer159 @return La cha �ne nettoy�e (escaped string)157 /** Nettoye une chaine de caractère dans un format compatible bytea. 158 @param $chaine La chaéne de caractère à nettoyer 159 @return La chaéne nettoyée (escaped string) 160 160 */ 161 161 … … 166 166 } 167 167 168 /** Reconverti une chaine de caract �re en format bytea pur.169 @param $chaine La cha �ne de caract�re170 @return La cha �ne reconvertie en format original (unescaped string)168 /** Reconverti une chaine de caractère en format bytea pur. 169 @param $chaine La chaéne de caractère 170 @return La chaéne reconvertie en format original (unescaped string) 171 171 */ 172 172 … … 177 177 } 178 178 179 /**Ex �cute une requ�te pour laquelle on pr�voit un r�sultat UNIQUE. Si le r�sultat n'est pas unique, un avertissement est affich�180 @param $sql Requ�te SELECT � ex�cuter181 @param $retVal un array des colonnes de la rang �e retourn�e, NULL si aucun r�sultats.182 @param $debug Si TRUE, affiche les r �sultats bruts de la requ�te183 @return TRUE si la requete a �t� effectu�e avec succ�s, FALSE autrement.179 /**Exécute une requête pour laquelle on prévoit un résultat UNIQUE. Si le résultat n'est pas unique, un avertissement est affiché 180 @param $sql requête SELECT à exécuter 181 @param $retVal un array des colonnes de la rangée retournée, NULL si aucun résultats. 182 @param $debug Si TRUE, affiche les résultats bruts de la requête 183 @return TRUE si la requete a été effectuée avec succés, FALSE autrement. 184 184 */ 185 185 function ExecSqlUniqueRes($sql, & $retVal, $debug=false) … … 188 188 if ($debug == TRUE) 189 189 { 190 echo "<hr /><p> Requ�te: <br><pre>$sql</pre></p>";190 echo "<hr /><p>requête: <br><pre>$sql</pre></p>"; 191 191 } 192 192 $connection = $this -> connexionDb(NULL); … … 214 214 if ($debug == TRUE) 215 215 { 216 echo "<P>Temps �coul� pour la requ�te SQL: $sql_timetaken seconde(s)</P>\n";216 echo "<P>Temps écoulé pour la requête SQL: $sql_timetaken seconde(s)</P>\n"; 217 217 } 218 218 219 219 if ($result == FALSE) 220 220 { 221 echo "<p>ExecuterSqlResUnique(): ERREUR: Lors de l'ex �cution de la requ�te SQL:<br>$sql</p>";221 echo "<p>ExecuterSqlResUnique(): ERREUR: Lors de l'exécution de la requête SQL:<br>$sql</p>"; 222 222 echo "<p>L'erreur est:<br>".pg_last_error($connection)."</p>"; 223 223 $retval = FALSE; … … 229 229 if (pg_num_rows($result) > 1) 230 230 { 231 echo "<p>ExecuterSqlResUnique(): ERREUR: Lors de l'ex �cution de la requ�te SQL:<br>$sql</p>";232 echo "<p>Il y a ".pg_num_rows($result)." r �sultats alors qu'il ne devrait y en avoir qu'un seul.</p>";231 echo "<p>ExecuterSqlResUnique(): ERREUR: Lors de l'exécution de la requête SQL:<br>$sql</p>"; 232 echo "<p>Il y a ".pg_num_rows($result)." résultats alors qu'il ne devrait y en avoir qu'un seul.</p>"; 233 233 $retval = FALSE; 234 234 $debug = true; … … 239 239 { 240 240 $num_rows = pg_num_rows($result); 241 echo "<p>ExecuterSqlResUnique(): DEBUG: Il y a $num_rows r �sultats:<br><TABLE class='spreadsheet'>";241 echo "<p>ExecuterSqlResUnique(): DEBUG: Il y a $num_rows résultats:<br><TABLE class='spreadsheet'>"; 242 242 if ($returnResults != NULL) 243 243 { 244 //On affiche l'en-t �te des colonnes une seule fois*/244 //On affiche l'en-téte des colonnes une seule fois*/ 245 245 echo "<TR class='spreadsheet'>"; 246 246 while (list ($col_name, $col_content) = each($returnResults[0])) … … 268 268 } 269 269 270 /**Ex �cute une requ�te visant � modifier la base de donn�e, et donc ne retournant aucun r�sultat.271 @param $sql Requ�te SELECT � ex�cuter272 @param $debug Si TRUE, affiche la requ �te brute270 /**Exécute une requête visant à modifier la base de donnée, et donc ne retournant aucun résultat. 271 @param $sql requête SELECT à exécuter 272 @param $debug Si TRUE, affiche la requête brute 273 273 */ 274 274 function ExecSqlUpdate($sql, $debug=false) … … 277 277 if ($debug == TRUE) 278 278 { 279 echo "<hr /><p>ExecuterSqlUpdate(): DEBUG: Requ�te:<br>\n<pre>$sql</pre></p>\n";279 echo "<hr /><p>ExecuterSqlUpdate(): DEBUG: requête:<br>\n<pre>$sql</pre></p>\n"; 280 280 } 281 281 … … 302 302 if ($debug == TRUE) 303 303 { 304 echo "<P>".pg_affected_rows($result)." rang �es affect�es par la requ�te SQL<br>\n";305 echo "Temps �coul�: $sql_timetaken seconde(s)</P>\n";304 echo "<P>".pg_affected_rows($result)." rangées affectées par la requête SQL<br>\n"; 305 echo "Temps écoulé: $sql_timetaken seconde(s)</P>\n"; 306 306 } 307 307 308 308 if ($result == FALSE) 309 309 { 310 echo "<p>ExecuterSqlResUnique(): ERREUR: Lors de l'ex �cution de la requ�te SQL:<br><pre>$sql</pre></p>";310 echo "<p>ExecuterSqlResUnique(): ERREUR: Lors de l'exécution de la requête SQL:<br><pre>$sql</pre></p>"; 311 311 echo "<p>L'erreur est:<br>".pg_last_error()."<br>".pg_result_error($result)."</p>"; 312 312 } … … 315 315 if ($debug == TRUE) 316 316 { 317 echo "<p>ExecuterSqlUpdate(): DEBUG: ".pg_affected_rows($result)." rang �e(s) affect�e(s)</p><hr />\n";317 echo "<p>ExecuterSqlUpdate(): DEBUG: ".pg_affected_rows($result)." rangée(s) affectée(s)</p><hr />\n"; 318 318 } 319 319 } -
trunk/wifidog-auth/wifidog/classes/Content.php
r550 r551 111 111 if ($file != '.' && $file != '..') 112 112 { 113 if (preg_match("/^.*\.php$/", $file)>0)114 { 115 $tab[$i] = $file;116 $i ++;113 if (preg_match("/^.*\.php$/", $file) > 0) 114 { 115 $tab[$i] = $file; 116 $i ++; 117 117 } 118 118 } … … 134 134 * @return html markup 135 135 */ 136 static function getNewContent Interface($user_prefix, $content_type = null)136 static function getNewContentUI($user_prefix, $content_type = null) 137 137 { 138 138 global $db; … … 179 179 * @return the Content object, or null if the user didn't greate one 180 180 */ 181 static function processNewContent Interface($user_prefix)181 static function processNewContentUI($user_prefix) 182 182 { 183 183 $object = null; … … 245 245 $content_id = "'".$this->id."'"; 246 246 $user_id = "'".$db->EscapeString($user->getId())."'"; 247 if ($is_author == true) 248 { 249 $is_author = 'TRUE'; 250 } 251 else 252 { 253 $is_author = 'FALSE'; 254 } 247 $is_author ? $is_author = 'TRUE' : $is_author = 'FALSE'; 255 248 $sql = "INSERT INTO content_has_owners (content_id, user_id, is_author) VALUES ($content_id, $user_id, $is_author)"; 256 249 257 250 if (!$db->ExecSqlUpdate($sql, false)) 258 251 { 259 throw new Exception(_('Unable to insert the new Owner into database !'));252 throw new Exception(_('Unable to insert the new Owner into database.')); 260 253 } 261 254 … … 263 256 } 264 257 258 /** Remove an owner of the content 259 * @param $user The user to be removed from the owners list 260 */ 261 public function deleteOwner(User $user, $is_author = false) 262 { 263 global $db; 264 $content_id = "'".$this->id."'"; 265 $user_id = "'".$db->EscapeString($user->getId())."'"; 266 267 $sql = "DELETE FROM content_has_owners WHERE content_id=$content_id AND user_id=$user_id"; 268 269 if (!$db->ExecSqlUpdate($sql, false)) 270 { 271 throw new Exception(_('Unable to remove the owner from the database.')); 272 } 273 274 return true; 275 } 276 265 277 /** Check if a user is one of the owners of the object 266 * @return true on success, false on failure */ 267 public function isOwner(User $user) 268 { 269 echo "<h1>WRITEME</h1>"; 270 return false; 278 * @param $user User object: the user to be tested. 279 * @return true if the user is a owner, false if he isn't of the user is null */ 280 public function isOwner($user) 281 { 282 global $db; 283 $retval = false; 284 if ($user != null) 285 { 286 $user_id = $db->EscapeString($user->GetId()); 287 $sql = "SELECT * FROM content_has_owners WHERE content_id='$this->id' AND user_id='$user_id'"; 288 $db->ExecSqlUniqueRes($sql, $content_owner_row, false); 289 if ($content_owner_row != null) 290 { 291 $retval = true; 292 } 293 } 294 295 return $retval; 271 296 } 272 297 /** Get the authors of the Content … … 274 299 public function getAuthors() 275 300 { 276 echo "<h1> WRITEME</h1>";301 echo "<h1>getAuthors():WRITEME</h1>"; 277 302 return false; 278 303 } … … 296 321 public function getUserUI($subclass_user_interface = null) 297 322 { 298 $html = '';299 $html .= "<div class='user_ui_container'>\n";323 $html = ''; 324 $html .= "<div class='user_ui_container'>\n"; 300 325 $html .= "<div class='user_ui_object_class'>Content (".get_class($this)." instance)</div>\n"; 301 $html .= $subclass_user_interface;326 $html .= $subclass_user_interface; 302 327 $html .= "</div>\n"; 303 328 return $html; 304 329 } 305 330 306 331 /** Retreives the admin interface of this object. Anything that overrides this method should call the parent method with it's output at the END of processing. 307 332 * @param $subclass_admin_interface Html content of the interface element of a children … … 309 334 public function getAdminUI($subclass_admin_interface = null) 310 335 { 311 global $db;336 global $db; 312 337 $html = ''; 313 338 $html .= "<div class='admin_container'>\n"; … … 333 358 if (empty ($this->content_row['title'])) 334 359 { 335 $html .= self :: getNewContent Interface("title_{$this->id}_new");360 $html .= self :: getNewContentUI("title_{$this->id}_new"); 336 361 } 337 362 else … … 345 370 } 346 371 $html .= "</div>\n"; 347 348 /* is_persistent */349 $html .= "<div class='admin_section_container'>\n";350 $html .= "<div class='admin_section_title'>Is persistent (reusable and read-only)?: </div>\n";351 $html .= "<div class='admin_section_data'>\n";352 $name = "content_".$this->id."_is_persistent";353 $this->isPersistent()?$checked='CHECKED':$checked='';354 $html .= "<input type='checkbox' name='$name' $checked>\n";355 $html .= "</div>\n";356 $html .= "</div>\n";357 372 373 /* is_persistent */ 374 $html .= "<div class='admin_section_container'>\n"; 375 $html .= "<div class='admin_section_title'>Is persistent (reusable and read-only)?: </div>\n"; 376 $html .= "<div class='admin_section_data'>\n"; 377 $name = "content_".$this->id."_is_persistent"; 378 $this->isPersistent() ? $checked = 'CHECKED' : $checked = ''; 379 $html .= "<input type='checkbox' name='$name' $checked>\n"; 380 $html .= "</div>\n"; 381 $html .= "</div>\n"; 382 358 383 /* description */ 359 384 $html .= "<div class='admin_section_container'>\n"; … … 361 386 if (empty ($this->content_row['description'])) 362 387 { 363 $html .= self :: getNewContent Interface("description_{$this->id}_new");388 $html .= self :: getNewContentUI("description_{$this->id}_new"); 364 389 } 365 390 else … … 379 404 if (empty ($this->content_row['project_info'])) 380 405 { 381 $html .= self :: getNewContent Interface("project_info_{$this->id}_new");406 $html .= self :: getNewContentUI("project_info_{$this->id}_new"); 382 407 } 383 408 else … … 397 422 if (empty ($this->content_row['sponsor_info'])) 398 423 { 399 $html .= self :: getNewContent Interface("sponsor_info_{$this->id}_new");424 $html .= self :: getNewContentUI("sponsor_info_{$this->id}_new"); 400 425 } 401 426 else … … 410 435 $html .= "</div>\n"; 411 436 437 /* content_has_owners */ 438 $html .= "<div class='admin_section_container'>\n"; 439 $html .= "<span class='admin_section_title'>"._("Content owner list")."</span>\n"; 440 $html .= "<ul class='admin_section_list'>\n"; 441 442 global $db; 443 $sql = "SELECT * FROM content_has_owners WHERE content_id='$this->id'"; 444 $db->ExecSql($sql, $content_owner_rows, false); 445 if ($content_owner_rows != null) 446 { 447 foreach ($content_owner_rows as $content_owner_row) 448 { 449 $html .= "<li class='admin_section_list_item'>\n"; 450 $html .= "<div class='admin_section_data'>\n"; 451 $user = User :: getUserByID($content_owner_row['user_id']); 452 453 $html .= $user->getUserListUI(); 454 $name = "content_".$this->id."_owner_".$user->GetId()."_is_author"; 455 $html .= " Is content author? "; 456 457 $content_owner_row['is_author'] == 't' ? $checked = 'CHECKED' : $checked = ''; 458 $html .= "<input type='checkbox' name='$name' $checked>\n"; 459 $html .= "</div>\n"; 460 $html .= "<div class='admin_section_tools'>\n"; 461 $name = "content_".$this->id."_owner_".$user->GetId()."_remove"; 462 $html .= "<input type='submit' name='$name' value='"._("Remove")."' onclick='submit();'>"; 463 $html .= "</div>\n"; 464 $html .= "</li>\n"; 465 } 466 } 467 468 $html .= "<li class='admin_section_list_item'>\n"; 469 $html .= "<div class='admin_section_data'>\n"; 470 $html .= User :: getSelectUserUI("content_{$this->id}_new_owner"); 471 $html .= "</div>\n"; 472 $html .= "<div class='admin_section_tools'>\n"; 473 $name = "content_{$this->id}_add_owner_submit"; 474 $value = _("Add owner"); 475 $html .= "<input type='submit' name='$name' value='$value' onclick='submit();'>"; 476 $html .= "</div>\n"; 477 $html .= "</li>\n"; 478 $html .= "</ul>\n"; 479 $html .= "</div>\n"; 412 480 } 413 481 $html .= $subclass_admin_interface; … … 432 500 if (empty ($this->content_row['title'])) 433 501 { 434 $title = self :: processNewContent Interface("title_{$this->id}_new");502 $title = self :: processNewContentUI("title_{$this->id}_new"); 435 503 if ($title != null) 436 504 { … … 453 521 } 454 522 } 455 456 /* is_persistent */457 $name = "content_".$this->id."_is_persistent";458 !empty($_REQUEST[$name])?$this->setIsPersistent(true):$this->setIsPersistent(false);523 524 /* is_persistent */ 525 $name = "content_".$this->id."_is_persistent"; 526 !empty ($_REQUEST[$name]) ? $this->setIsPersistent(true) : $this->setIsPersistent(false); 459 527 460 528 /* description */ 461 529 if (empty ($this->content_row['description'])) 462 530 { 463 $description = self :: processNewContent Interface("description_{$this->id}_new");531 $description = self :: processNewContentUI("description_{$this->id}_new"); 464 532 if ($description != null) 465 533 { … … 486 554 if (empty ($this->content_row['project_info'])) 487 555 { 488 $project_info = self :: processNewContent Interface("project_info_{$this->id}_new");556 $project_info = self :: processNewContentUI("project_info_{$this->id}_new"); 489 557 if ($project_info != null) 490 558 { … … 511 579 if (empty ($this->content_row['sponsor_info'])) 512 580 { 513 $sponsor_info = self :: processNewContent Interface("sponsor_info_{$this->id}_new");581 $sponsor_info = self :: processNewContentUI("sponsor_info_{$this->id}_new"); 514 582 if ($sponsor_info != null) 515 583 { … … 532 600 } 533 601 } 602 /* content_has_owners */ 603 $sql = "SELECT * FROM content_has_owners WHERE content_id='$this->id'"; 604 $db->ExecSql($sql, $content_owner_rows, false); 605 if ($content_owner_rows != null) 606 { 607 foreach ($content_owner_rows as $content_owner_row) 608 { 609 $user = User :: getUserByID($content_owner_row['user_id']); 610 $user_id = $user->getId(); 611 $name = "content_".$this->id."_owner_".$user->GetId()."_remove"; 612 if (!empty ($_REQUEST[$name])) 613 { 614 $this->deleteOwner($user); 615 } 616 else 617 { 618 $name = "content_".$this->id."_owner_".$user->GetId()."_is_author"; 619 $content_owner_row['is_author'] == 't' ? $is_author = true : $is_author = false; 620 !empty ($_REQUEST[$name]) ? $should_be_author = true : $should_be_author = false; 621 if ($is_author != $should_be_author) 622 { 623 $should_be_author ? $is_author_sql = 'TRUE' : $is_author_sql = 'FALSE'; 624 $sql = "UPDATE content_has_owners SET is_author=$is_author_sql WHERE content_id='$this->id' AND user_id='$user_id'"; 625 626 if (!$db->ExecSqlUpdate($sql, false)) 627 { 628 throw new Exception(_('Unable to set as author in the database.')); 629 } 630 631 } 632 633 } 634 } 635 } 636 $user = User :: processSelectUserUI("content_{$this->id}_new_owner"); 637 $name = "content_{$this->id}_add_owner_submit"; 638 if (!empty ($_REQUEST[$name]) && $user != null) 639 { 640 $this->addOwner($user); 641 } 534 642 535 643 } 536 644 } 537 538 645 /** Subscribe to the project 539 646 * @return true on success, false on failure */ … … 550 657 return false; 551 658 } 552 553 /** Persistent (or read-only) content is meant for re-use. It will not be deleted when the delete() method is called. When a containing element (ContentGroup, ContentGroupElement) is deleted, it calls delete on all the content it includes. If the content is persistent, only the association will be removed.554 * @return true or false */659 660 /** Persistent (or read-only) content is meant for re-use. It will not be deleted when the delete() method is called. When a containing element (ContentGroup, ContentGroupElement) is deleted, it calls delete on all the content it includes. If the content is persistent, only the association will be removed. 661 * @return true or false */ 555 662 public function isPersistent() 556 663 { 557 if ($this->content_row['is_persistent']=='t')664 if ($this->content_row['is_persistent'] == 't') 558 665 { 559 666 $retval = true; … … 561 668 else 562 669 { 563 $retval =false;670 $retval = false; 564 671 } 565 672 return $retval; 566 673 } 567 674 568 675 /** Set if the content group is persistent 569 676 * @param $is_locative_content true or false … … 571 678 public function setIsPersistent($is_persistent) 572 679 { 573 if ($is_persistent!=$this->isPersistent())/* Only update database if there is an actual change */574 { 575 $is_persistent?$is_persistent_sql='TRUE':$is_persistent_sql='FALSE';576 577 global $db;578 $db->ExecSqlUpdate("UPDATE content SET is_persistent = $is_persistent_sql WHERE content_id = '$this->id'", false);579 $this->refresh();580 } 581 582 } 583 584 /** Reloads the object from the database. Should normally be called after a set operation585 * @todo Implement proper Access control */586 protected function refresh()587 { 680 if ($is_persistent != $this->isPersistent()) /* Only update database if there is an actual change */ 681 { 682 $is_persistent ? $is_persistent_sql = 'TRUE' : $is_persistent_sql = 'FALSE'; 683 684 global $db; 685 $db->ExecSqlUpdate("UPDATE content SET is_persistent = $is_persistent_sql WHERE content_id = '$this->id'", false); 686 $this->refresh(); 687 } 688 689 } 690 691 /** Reloads the object from the database. Should normally be called after a set operation 692 * @todo Implement proper Access control */ 693 protected function refresh() 694 { 588 695 $this->__construct($this->id); 589 696 } 590 697 591 698 /** Delete this Content from the database 592 699 * @todo Implement proper Access control */ 593 public function delete() 594 { 595 if($this->isPersistent()==false) 596 { 597 global $db; 598 $sql = "DELETE FROM content WHERE content_id='$this->id'"; 599 $db->ExecSqlUpdate($sql, false); 700 public function delete() 701 { 702 if ($this->isPersistent() == false) 703 { 704 global $db; 705 if (!$this->isOwner(User :: getCurrentUser())) 706 { 707 throw new Exception(_("Access denied (not owner of content)")); 708 } 709 $sql = "DELETE FROM content WHERE content_id='$this->id'"; 710 $db->ExecSqlUpdate($sql, false); 600 711 } 601 712 } -
trunk/wifidog-auth/wifidog/classes/Content/ContentGroup.php
r550 r551 179 179 } 180 180 $html .= "<li class='admin_section_list_item'>\n"; 181 $html .= self :: getNewContent Interface("content_group_{$this->id}_new_element");181 $html .= self :: getNewContentUI("content_group_{$this->id}_new_element"); 182 182 $html .= "</li>\n"; 183 183 $html .= "</ul>\n"; … … 216 216 } 217 217 218 /* We explicitely call the ContentGroupElement version of processNewContent Interface*/219 $new_element = ContentGroupElement :: processNewContent Interface("content_group_{$this->id}_new_element", $this);218 /* We explicitely call the ContentGroupElement version of processNewContentUI */ 219 $new_element = ContentGroupElement :: processNewContentUI("content_group_{$this->id}_new_element", $this); 220 220 } 221 221 /**Get all elements -
trunk/wifidog-auth/wifidog/classes/Content/ContentGroupElement.php
r550 r551 32 32 private $content_group_element_row; 33 33 34 /** Thelike the same class as defined in Content, this methos will create a ContentGroupElement based on the content type specified by getNewContentInterface34 /** Like the same method as defined in Content, this method will create a ContentGroupElement based on the content type specified by getNewContentUI 35 35 * @param $user_prefix A identifier provided by the programmer to recognise it's generated form 36 36 * @param $content_group Must be present 37 37 * @return the ContentGroup object, or null if the user didn't greate one 38 38 */ 39 static function processNewContent Interface($user_prefix, ContentGroup $content_group)39 static function processNewContentUI($user_prefix, ContentGroup $content_group) 40 40 { 41 41 global $db; … … 50 50 51 51 $name = "get_new_content_{$user_prefix}_content_type"; 52 $content_type = FormSelectGenerator :: getResult($name, null);53 $displayed_content_object = self :: createNewContent($content_type);54 52 55 53 $content_id = get_guid(); … … 67 65 } 68 66 $content_group_element_object = self :: getContent($content_id); 67 68 $content_type = FormSelectGenerator :: getResult($name, null); 69 if($content_type!='ContentGroupElement') 70 { 71 $displayed_content_object = self :: createNewContent($content_type); 69 72 $content_group_element_object->replaceDisplayedContent($displayed_content_object); 73 } 70 74 } 71 75 return $content_group_element_object; … … 84 88 if ($row == null) 85 89 { 86 $db->ExecSqlUniqueRes($sql_select, $row, false);87 if ($row == null)88 {89 90 throw new Exception(_("The content with the following id could not be found in the database: ").$content_id); 90 }91 92 91 } 93 92 $this->content_group_element_row = $row; … … 164 163 if (empty ($this->content_group_element_row['displayed_content_id'])) 165 164 { 166 $html .= self :: getNewContent Interface("content_group_element_{$this->id}_new_displayed_content");165 $html .= self :: getNewContentUI("content_group_element_{$this->id}_new_displayed_content"); 167 166 } 168 167 else … … 248 247 if (empty ($this->content_group_element_row['displayed_content_id'])) 249 248 { 250 $displayed_content = Content :: processNewContent Interface("content_group_element_{$this->id}_new_displayed_content");249 $displayed_content = Content :: processNewContentUI("content_group_element_{$this->id}_new_displayed_content"); 251 250 if ($displayed_content != null) 252 251 { … … 291 290 } 292 291 292 /** Override the method in Content. The owners of the content element are always considered to be the ContentGroup's 293 * @param $user User object: the user to be tested. 294 * @return true if the user is a owner, false if he isn't of the user is null */ 295 public function isOwner($user) 296 { 297 $content_group = Content::getContent($this->content_group_element_row['content_group_id']); 298 return $content_group->isOwner($user); 299 } 300 293 301 /** Delete this Content from the database 294 302 * @todo Implement proper Access control */ -
trunk/wifidog-auth/wifidog/classes/Content/Langstring.php
r550 r551 31 31 error_reporting(E_ALL); 32 32 33 /** Représente un Langstring en particulier, ne créez pas un objet langstrings si wous n'en avez pas spécifiquement besoin33 /** Représente un Langstring en particulier, ne créez pas un objet langstrings si vous n'en avez pas spécifiquement besoin 34 34 */ 35 35 class Langstring extends Content … … 54 54 55 55 $sql = "SELECT value, locales_id, \n"; 56 $sql .= Locale :: getSqlCaseStringSelect( User :: getCurrentUser()->getPreferedLocale());56 $sql .= Locale :: getSqlCaseStringSelect(LocaleList::GetDefault()); 57 57 $sql .= " as score FROM langstring_entries WHERE langstring_entries.langstrings_id = '{$this->id}' ORDER BY score LIMIT 1"; 58 58 $this->mBd->ExecSqlUniqueRes($sql, $row, false); … … 169 169 170 170 //Nouvelles chaîne 171 $locale = User :: getCurrentUser()->getPreferedLocale();171 $locale = LocaleList::GetDefault(); 172 172 $html .= "<li class='admin_section_list_item'>\n"; 173 173 $html .= $liste_languages->GenererFormSelect($locale, "langstrings_".$this->id."_substring_new_language", 'Langstring::AfficherInterfaceAdmin', TRUE); -
trunk/wifidog-auth/wifidog/classes/LocaleList.php
r545 r551 1 1 <?php 2 2 3 /********************************************************************\ 3 4 * This program is free software; you can redistribute it and/or * … … 40 41 { 41 42 //parent::__construct(); 42 global $db;43 $this->mBd =&$db;//for backward compatibility43 global $db; 44 $this->mBd = & $db; //for backward compatibility 44 45 } 45 46 … … 63 64 $retval = ""; 64 65 $sql = "SELECT * FROM locales ORDER BY locales_id"; 65 $this -> mBd ->ExecSql($sql, $resultats, FALSE);66 $this->mBd->ExecSql($sql, $resultats, FALSE); 66 67 67 68 $retval = ""; 68 $retval .= "<select name='$prefixeNomSelectUsager$prefixeNomSelectObjet'>\n";69 $retval .= "<select name='$prefixeNomSelectUsager$prefixeNomSelectObjet'>\n"; 69 70 if ($permetValeurNulle == true) 70 71 { 71 $retval .= "<option value=''>---</option>\n";72 $retval .= "<option value=''>---</option>\n"; 72 73 } 73 74 //echo "$selectedClefPrimaire"; 74 75 while (list ($key, $value) = each($resultats)) 75 76 { 76 $retval .= "<option ";77 $retval .= "<option "; 77 78 78 79 //echo "$value[$champClefPrimaire],$selectedClefPrimaire<br>"; 79 if ($value['locales_id'] == $selectedClefPrimaire || $selectedClefPrimaire == null && $selectedClefPrimaire == $this ->GetDefault())80 if ($value['locales_id'] == $selectedClefPrimaire || $selectedClefPrimaire == null && $selectedClefPrimaire == $this->GetDefault()) 80 81 { 81 $retval .= "SELECTED ";82 $retval .= "SELECTED "; 82 83 } 83 $retval .= "value='$value[locales_id]'>$value[locales_id]";84 $retval .= "</option>\n";84 $retval .= "value='$value[locales_id]'>$value[locales_id]"; 85 $retval .= "</option>\n"; 85 86 } 86 $retval .= "</select>\n";87 $retval .= "</select>\n"; 87 88 return $retval; 88 89 } 89 90 91 90 92 91 /**Retourne le language par défaut, selon les préférences de l'usager 93 92 */ 94 93 function GetDefault() 95 {global $session; 96 97 return User::getCurrentUser()->getPreferedLocale(); 94 { 95 global $session; 96 97 if ($user = User :: getCurrentUser()) 98 { 99 $locale = $user->getPreferedLocale(); 100 } 101 else 102 { 103 $locale = $session->get('SESS_LANGUAGE_VAR'); 104 if (empty ($locale)) 105 { 106 $locale = DEFAULT_LANG; 107 } 108 } 109 return $locale; 98 110 } 99 111 100 112 /**Retourne la liste de toutes les clef primairess 101 113 */ 102 114 function GetListeClefsPrimaires() 103 115 { 104 $this -> mBd ->ExecuterSql("SELECT locales_id FROM locales", $resultats, FALSE);116 $this->mBd->ExecuterSql("SELECT locales_id FROM locales", $resultats, FALSE); 105 117 106 118 foreach ($resultats as $resultat) 107 119 { 108 $retval[] =$resultat['locales_id'];120 $retval[] = $resultat['locales_id']; 109 121 } 110 122 return $retval; … … 117 129 @param $entree ID de l'entree de vocabulaire 118 130 */ 119 function Export($export_format, & $document, $parent, $entree = null)120 { 131 function Export($export_format, & $document, $parent, $entree = null) 132 { 121 133 if ($entree != null) 122 134 { 123 135 $langue = new Locale($entree); 124 $langue ->Export($export_format, $document, $parent);136 $langue->Export($export_format, $document, $parent); 125 137 } 126 138 } 127 139 128 140 function isEmpty() 129 141 { 130 142 return false; 131 143 } 132 144 133 145 /** 134 146 * By definition it cannot be considerend empty, so it's always compliant' … … 139 151 return COMPLIANT_MASK; 140 152 } 141 153 142 154 } /* end class LocaleList */ 143 155 ?> 156 -
trunk/wifidog-auth/wifidog/classes/User.php
r545 r551 1 1 <?php 2 2 3 /********************************************************************\ 3 4 * This program is free software; you can redistribute it and/or * … … 24 25 25 26 require_once BASEPATH.'include/common.php'; 26 27 require_once BASEPATH.'classes/Network.php'; 27 28 /** Abstract a User. */ 28 29 class User … … 41 42 return $object; 42 43 } 43 44 44 45 /** Instantiate the current user 45 46 * @return a User object, or null if there was an error … … 49 50 require_once BASEPATH.'classes/Session.php'; 50 51 $session = new Session(); 51 $user =null;52 $user = null; 52 53 try 53 54 { 54 55 $user = new User($session->get(SESS_USER_ID_VAR)); 55 56 } 56 catch (Exception $e)57 catch (Exception $e) 57 58 { 58 59 /**If any problem occurs, the user should be considered logged out*/ … … 61 62 return $user; 62 63 } 63 64 64 65 /** Instantiate a user object 65 66 * @param $username The username of the user … … 76 77 $db->ExecSqlUniqueRes("SELECT user_id FROM users WHERE username = '$username_str' AND account_origin = '$account_origin_str'", $user_info, false); 77 78 78 if ($user_info != null)79 if ($user_info != null) 79 80 $object = new self($user_info['user_id']); 80 81 return $object; 81 82 } 82 83 83 84 /** Instantiate a user object 84 85 * @param $email The email of the user … … 95 96 $db->ExecSqlUniqueRes("SELECT user_id FROM users WHERE email = '$email_str' AND account_origin = '$account_origin_str'", $user_info, false); 96 97 97 if ($user_info != null)98 if ($user_info != null) 98 99 $object = new self($user_info['user_id']); 99 100 return $object; … … 216 217 $email_str = $db->EscapeString($email); 217 218 /** 218 * utf8_decode is used for backward compatibility with old passwords219 * containing special characters.220 * Conversion from UTF-8 to ISO-8859-1 is done to match the MD5 hash221 */219 * utf8_decode is used for backward compatibility with old passwords 220 * containing special characters. 221 * Conversion from UTF-8 to ISO-8859-1 is done to match the MD5 hash 222 */ 222 223 $password_hash = $db->EscapeString(User :: passwordHash(utf8_decode($password))); 223 224 $status = ACCOUNT_STATUS_VALIDATION; … … 239 240 if ($row == null) 240 241 { 241 throw new Exception(_(" user_id '{$object_id_str}'could not be found in the database"));242 throw new Exception(_("User id: ").$object_id_str._(" could not be found in the database")); 242 243 } 243 244 $this->mRow = $row; … … 250 251 } 251 252 253 /** Get a user display suitable for a user list. Will include link to the user profile. */ 254 function getUserListUI() 255 { 256 $html = ''; 257 $html .= $this->getUserName(); 258 return $html; 259 } 260 252 261 function getUsername() 253 262 { … … 260 269 } 261 270 262 /**What locale (language) does the user prefer?263 * @todo Save in the database */271 /**What locale (language) does the user prefer? 272 * @todo Save in the database */ 264 273 public function getPreferedLocale() 265 274 { … … 267 276 //return $this->mRow['prefered_locale']; 268 277 $locale = $session->get('SESS_LANGUAGE_VAR'); 269 if (empty($locale))270 { 271 $locale =DEFAULT_LANG;278 if (empty ($locale)) 279 { 280 $locale = DEFAULT_LANG; 272 281 } 273 282 return $locale; … … 303 312 function isUserValid(& $errmsg = null) 304 313 { 305 global $db;314 global $db; 306 315 $retval = false; 307 316 $account_status = $this->getAccountStatus(); … … 377 386 { 378 387 global $db; 379 388 380 389 $new_password_hash = User :: passwordHash(utf8_decode($password)); 381 390 if (!($update = $db->ExecSqlUpdate("UPDATE users SET pass='$new_password_hash' WHERE user_id='{$this->mId}'"))) … … 410 419 { 411 420 $username = $this->getUsername(); 412 $headers = 'MIME-Version: 1.0' ."\r\n";413 $headers .= 'Content-type: text/plain; charset=UTF-8' ."\r\n";421 $headers = 'MIME-Version: 1.0'."\r\n"; 422 $headers .= 'Content-type: text/plain; charset=UTF-8'."\r\n"; 414 423 $headers .= "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 415 424 $subject = HOTSPOT_NETWORK_NAME._(" lost username request"); 416 425 $body = _("Hello,\nYou have requested that the authentication server send you your username:\nUsername: ").$username._("\n\nHave a nice day,\nThe Team"); 417 426 418 427 mail($this->getEmail(), $subject, $body, $headers); 419 428 } … … 433 442 else 434 443 { 435 $headers = 'MIME-Version: 1.0' ."\r\n";436 $headers .= 'Content-type: text/plain; charset=UTF-8' ."\r\n";444 $headers = 'MIME-Version: 1.0'."\r\n"; 445 $headers .= 'Content-type: text/plain; charset=UTF-8'."\r\n"; 437 446 $headers .= "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 438 447 $subject = HOTSPOT_NETWORK_NAME._(" new user validation"); 439 448 $url = "http://".$_SERVER["SERVER_NAME"]."/validate.php?user_id=".$this->getId()."&token=".$this->getValidationToken(); 440 449 $body = _("Hello,\nPlease follow the link below to validate your account.\n").$url._("\n\nThank you,\nThe Team."); 441 450 442 451 mail($this->getEmail(), $subject, $body, $headers); 443 452 } … … 452 461 $this->setPassword($new_password); 453 462 $username = $this->getUsername(); 454 455 $headers = 'MIME-Version: 1.0' ."\r\n";456 $headers .= 'Content-type: text/plain; charset=UTF-8' ."\r\n";463 464 $headers = 'MIME-Version: 1.0'."\r\n"; 465 $headers .= 'Content-type: text/plain; charset=UTF-8'."\r\n"; 457 466 $headers .= "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 458 467 $subject = HOTSPOT_NETWORK_NAME._(" new password request"); 459 468 $body = _("Hello,\nYou have requested that the authentication server send you a new password:\nUsername: ").$username._("\nPassword: ").$new_password._("\n\nHave a nice day,\nThe Team"); 460 469 461 470 mail($this->getEmail(), $subject, $body, $headers); 462 471 } … … 471 480 } 472 481 473 function emailExists($id)482 public static function emailExists($id) 474 483 { 475 484 global $db; … … 510 519 } 511 520 521 /** Get an interface to add a user to a list 522 * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form 523 * @return html markup 524 */ 525 static function getSelectUserUI($user_prefix) 526 { 527 global $db; 528 $html = ''; 529 $html .= Network :: getSelectNetworkUI($user_prefix); 530 $name = "select_user_{$user_prefix}_username"; 531 $html .= "Username: \n"; 532 $html .= "<input type='text' name='$name' value=''>\n"; 533 return $html; 534 } 535 /** Get the selected user, IF one was selected and is valid 536 * @param $user_prefix A identifier provided by the programmer to recognise it's generated form 537 * @return the User object, or null if the user is invalid or none was selected 538 */ 539 static function processSelectUserUI($user_prefix) 540 { 541 $object = null; 542 $network = Network :: processSelectNetworkUI($user_prefix); 543 $name = "select_user_{$user_prefix}_username"; 544 $username = $_REQUEST[$name]; 545 return self::getUserByUsernameAndOrigin($username, $network->GetId()); 546 } 547 548 512 549 } // End class 513 550 ?> 551
