Changeset 551

Show
Ignore:
Timestamp:
04/18/05 01:19:16 (8 years ago)
Author:
benoitg
Message:

2005-04-18 Benoit Gr�goire <bock@…>

  • Much more complete admin, initial access control work.
Location:
trunk/wifidog-auth
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r550 r551  
     12005-04-18 Benoit Grégoire  <bock@step.polymtl.ca> 
     2        * Much more complete admin, initial access control work. 
     3 
    142005-04-15 Benoit Grégoire  <bock@step.polymtl.ca> 
    25        * 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  
    11<?php 
     2 
    23/********************************************************************\ 
    34 * This program is free software; you can redistribute it and/or    * 
     
    2526define('BASEPATH', '../'); 
    2627require_once 'admin_common.php'; 
    27 define ('CONTENT_ADMIN_HREF', 'content_admin.php'); 
     28define('CONTENT_ADMIN_HREF', 'content_admin.php'); 
    2829require_once BASEPATH.'classes/Content.php'; 
    2930require_once BASEPATH.'classes/Style.php'; 
     
    3435if (empty ($_REQUEST['action'])) 
    3536{ 
    36         $_REQUEST['action']='list_all_content'; 
     37        $_REQUEST['action'] = 'list_all_content'; 
    3738} 
    3839 
    3940if ($_REQUEST['action'] == 'list_all_content') 
    4041{ 
    41         $sql = "SELECT * FROM content"; 
     42        $sql = "SELECT * FROM content WHERE is_persistent=TRUE"; 
    4243        $db->ExecSql($sql, $results, false); 
    43         if($results!=null) 
     44        if ($results != null) 
    4445        { 
    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) 
    5150                { 
    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 
    5478                } 
    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"; 
    7480        } 
    7581        else 
     
    8288        $html .= '</form>'; 
    8389} 
    84         if ($_REQUEST['action'] == 'save') 
     90if ($_REQUEST['action'] == 'save') 
     91{ 
     92        $content = Content :: getContent($_REQUEST['content_id']); 
     93        $html .= $content->processAdminUI(); 
     94        $_REQUEST['action'] = 'edit'; 
     95} 
     96 
     97if ($_REQUEST['action'] == 'edit') 
     98{ 
     99        if (!empty ($_REQUEST['new_submit'])) 
    85100        { 
    86                         $content = Content :: getContent($_REQUEST['content_id']); 
    87                         $html .= $content->processAdminUI(); 
    88                         $_REQUEST['action'] = 'edit'; 
     101                $content = Content :: createNewContent(); 
     102                $content->setIsPersistent(true); 
    89103        } 
    90  
    91  
    92         if ($_REQUEST['action'] == 'edit') 
     104        else 
    93105        { 
    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        } 
    102108        $html .= "<form action='".CONTENT_ADMIN_HREF."' method='post'>"; 
    103109        $html .= "<input type='hidden' name='content_id' value='".$content->GetId()."'>\n"; 
     
    106112        $html .= "<input type=submit name='save_submit' value='"._("Save")."'>\n"; 
    107113        $html .= '</form>'; 
     114} 
    108115 
    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                         } 
     116if ($_REQUEST['action'] == 'delete') 
     117{ 
    123118 
    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} 
    138123 
    139                                 echo '</form>'; 
    140                         } 
    141                 } 
    142  
    143         } 
    144                         echo $html; 
    145                 $smarty->display("templates/footer.html"); 
     124echo $html; 
     125$smarty->display("templates/footer.html"); 
    146126?> 
    147127 
     128 
  • trunk/wifidog-auth/wifidog/classes/AbstractDbPostgres.php

    r545 r551  
    2323*/ 
    2424error_reporting(E_ALL); 
    25 /** Classe statique, permet d'abstraire la connexion � la base de donn�e 
     25/** Classe statique, permet d'abstraire la connexion à la base de donnée 
    2626 */ 
    2727class AbstractDb 
     
    4646        } 
    4747 
    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. 
     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. 
    5353        */ 
    5454        function ExecSql($sql, & $returnResults, $debug=false) 
     
    5757                if ($debug == TRUE) 
    5858                { 
    59                         echo "<hr /><p>ExecuterSql(): DEBUG: Requte:<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"; 
    6060                        $result = pg_query($connection, "EXPLAIN ".$sql); 
    6161 
     
    8989                if ($debug == TRUE) 
    9090                { 
    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"; 
    9292                } 
    9393 
    9494                if ($result == FALSE) 
    9595                { 
    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>"; 
    9797                        echo "<p>L'erreur est:<br>".pg_last_error($connection)."</p>"; 
    9898                        $returnResults = NULL; 
     
    112112                                { 
    113113                                        $num_rows = pg_num_rows($result); 
    114                                         echo "<p>ExecuterSql(): DEBUG: Il y a $num_rows rsultats:<br><TABLE class='spreadsheet'>"; 
     114                                        echo "<p>ExecuterSql(): DEBUG: Il y a $num_rows résultats:<br><TABLE class='spreadsheet'>"; 
    115115                                        if ($returnResults != NULL) 
    116116                                        { 
    117                                                 //On affiche l'en-tte des colonnes une seule fois*/ 
     117                                                //On affiche l'en-téte des colonnes une seule fois*/ 
    118118                                                echo "<TR class='spreadsheet'>"; 
    119119                                                while (list ($col_name, $col_content) = each($returnResults[0])) 
     
    139139        } 
    140140 
    141         /**Retourne une chaine de caractre 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 
     141        /**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 
    144144         */ 
    145145        function EscapeString($chaine) 
     
    155155        } 
    156156 
    157         /** Nettoye une chaine de caractre dans un format compatible bytea. 
    158          @param $chaine La cha�ne de caract�re � nettoyer 
    159          @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) 
    160160         */ 
    161161 
     
    166166        } 
    167167 
    168         /** Reconverti une chaine de caractre en format bytea pur. 
    169          @param $chaine La cha�ne de caract�re  
    170          @return La chane 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) 
    171171         */ 
    172172 
     
    177177        } 
    178178 
    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. 
     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. 
    184184         */ 
    185185        function ExecSqlUniqueRes($sql, & $retVal, $debug=false) 
     
    188188                if ($debug == TRUE) 
    189189                { 
    190                         echo "<hr /><p>Requ�te: <br><pre>$sql</pre></p>"; 
     190                        echo "<hr /><p>requête: <br><pre>$sql</pre></p>"; 
    191191                } 
    192192                $connection = $this -> connexionDb(NULL); 
     
    214214                if ($debug == TRUE) 
    215215                { 
    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"; 
    217217                } 
    218218 
    219219                if ($result == FALSE) 
    220220                { 
    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>"; 
    222222                        echo "<p>L'erreur est:<br>".pg_last_error($connection)."</p>"; 
    223223                        $retval = FALSE; 
     
    229229                        if (pg_num_rows($result) > 1) 
    230230                        { 
    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)." rsultats 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>"; 
    233233                                $retval = FALSE; 
    234234                                $debug = true; 
     
    239239                        { 
    240240                                $num_rows = pg_num_rows($result); 
    241                                 echo "<p>ExecuterSqlResUnique(): DEBUG: Il y a $num_rows rsultats:<br><TABLE class='spreadsheet'>"; 
     241                                echo "<p>ExecuterSqlResUnique(): DEBUG: Il y a $num_rows résultats:<br><TABLE class='spreadsheet'>"; 
    242242                                if ($returnResults != NULL) 
    243243                                { 
    244                                         //On affiche l'en-tte des colonnes une seule fois*/ 
     244                                        //On affiche l'en-téte des colonnes une seule fois*/ 
    245245                                        echo "<TR class='spreadsheet'>"; 
    246246                                        while (list ($col_name, $col_content) = each($returnResults[0])) 
     
    268268        } 
    269269 
    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�cuter 
    272          @param $debug Si TRUE, affiche la requte brute 
     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écuter 
     272         @param $debug Si TRUE, affiche la requête brute 
    273273         */ 
    274274        function ExecSqlUpdate($sql, $debug=false) 
     
    277277                if ($debug == TRUE) 
    278278                { 
    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"; 
    280280                } 
    281281 
     
    302302                if ($debug == TRUE) 
    303303                { 
    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"; 
    306306                } 
    307307 
    308308                if ($result == FALSE) 
    309309                { 
    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>"; 
    311311                        echo "<p>L'erreur est:<br>".pg_last_error()."<br>".pg_result_error($result)."</p>"; 
    312312                } 
     
    315315                        if ($debug == TRUE) 
    316316                        { 
    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"; 
    318318                        } 
    319319                } 
  • trunk/wifidog-auth/wifidog/classes/Content.php

    r550 r551  
    111111                                if ($file != '.' && $file != '..') 
    112112                                { 
    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 ++; 
    117117                                        } 
    118118                                } 
     
    134134         * @return html markup 
    135135         */ 
    136         static function getNewContentInterface($user_prefix, $content_type = null) 
     136        static function getNewContentUI($user_prefix, $content_type = null) 
    137137        { 
    138138                global $db; 
     
    179179         * @return the Content object, or null if the user didn't greate one 
    180180         */ 
    181         static function processNewContentInterface($user_prefix) 
     181        static function processNewContentUI($user_prefix) 
    182182        { 
    183183                $object = null; 
     
    245245                $content_id = "'".$this->id."'"; 
    246246                $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'; 
    255248                $sql = "INSERT INTO content_has_owners (content_id, user_id, is_author) VALUES ($content_id, $user_id, $is_author)"; 
    256249 
    257250                if (!$db->ExecSqlUpdate($sql, false)) 
    258251                { 
    259                         throw new Exception(_('Unable to insert the new Owner into database!')); 
     252                        throw new Exception(_('Unable to insert the new Owner into database.')); 
    260253                } 
    261254 
     
    263256        } 
    264257 
     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 
    265277        /** 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; 
    271296        } 
    272297        /** Get the authors of the Content 
     
    274299        public function getAuthors() 
    275300        { 
    276                 echo "<h1>WRITEME</h1>"; 
     301                echo "<h1>getAuthors():WRITEME</h1>"; 
    277302                return false; 
    278303        } 
     
    296321        public function getUserUI($subclass_user_interface = null) 
    297322        { 
    298                                 $html = ''; 
    299                                                 $html .= "<div class='user_ui_container'>\n"; 
     323                $html = ''; 
     324                $html .= "<div class='user_ui_container'>\n"; 
    300325                $html .= "<div class='user_ui_object_class'>Content (".get_class($this)." instance)</div>\n"; 
    301                                                 $html .= $subclass_user_interface; 
     326                $html .= $subclass_user_interface; 
    302327                $html .= "</div>\n"; 
    303328                return $html; 
    304329        } 
    305          
     330 
    306331        /** 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. 
    307332         * @param $subclass_admin_interface Html content of the interface element of a children 
     
    309334        public function getAdminUI($subclass_admin_interface = null) 
    310335        { 
    311                                 global $db; 
     336                global $db; 
    312337                $html = ''; 
    313338                $html .= "<div class='admin_container'>\n"; 
     
    333358                                if (empty ($this->content_row['title'])) 
    334359                                { 
    335                                         $html .= self :: getNewContentInterface("title_{$this->id}_new"); 
     360                                        $html .= self :: getNewContentUI("title_{$this->id}_new"); 
    336361                                } 
    337362                                else 
     
    345370                                } 
    346371                                $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 
    358383                                /* description */ 
    359384                                $html .= "<div class='admin_section_container'>\n"; 
     
    361386                                if (empty ($this->content_row['description'])) 
    362387                                { 
    363                                         $html .= self :: getNewContentInterface("description_{$this->id}_new"); 
     388                                        $html .= self :: getNewContentUI("description_{$this->id}_new"); 
    364389                                } 
    365390                                else 
     
    379404                                if (empty ($this->content_row['project_info'])) 
    380405                                { 
    381                                         $html .= self :: getNewContentInterface("project_info_{$this->id}_new"); 
     406                                        $html .= self :: getNewContentUI("project_info_{$this->id}_new"); 
    382407                                } 
    383408                                else 
     
    397422                                if (empty ($this->content_row['sponsor_info'])) 
    398423                                { 
    399                                         $html .= self :: getNewContentInterface("sponsor_info_{$this->id}_new"); 
     424                                        $html .= self :: getNewContentUI("sponsor_info_{$this->id}_new"); 
    400425                                } 
    401426                                else 
     
    410435                                $html .= "</div>\n"; 
    411436 
     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"; 
    412480                        } 
    413481                $html .= $subclass_admin_interface; 
     
    432500                                if (empty ($this->content_row['title'])) 
    433501                                { 
    434                                         $title = self :: processNewContentInterface("title_{$this->id}_new"); 
     502                                        $title = self :: processNewContentUI("title_{$this->id}_new"); 
    435503                                        if ($title != null) 
    436504                                        { 
     
    453521                                        } 
    454522                                } 
    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); 
    459527 
    460528                                /* description */ 
    461529                                if (empty ($this->content_row['description'])) 
    462530                                { 
    463                                         $description = self :: processNewContentInterface("description_{$this->id}_new"); 
     531                                        $description = self :: processNewContentUI("description_{$this->id}_new"); 
    464532                                        if ($description != null) 
    465533                                        { 
     
    486554                                if (empty ($this->content_row['project_info'])) 
    487555                                { 
    488                                         $project_info = self :: processNewContentInterface("project_info_{$this->id}_new"); 
     556                                        $project_info = self :: processNewContentUI("project_info_{$this->id}_new"); 
    489557                                        if ($project_info != null) 
    490558                                        { 
     
    511579                                if (empty ($this->content_row['sponsor_info'])) 
    512580                                { 
    513                                         $sponsor_info = self :: processNewContentInterface("sponsor_info_{$this->id}_new"); 
     581                                        $sponsor_info = self :: processNewContentUI("sponsor_info_{$this->id}_new"); 
    514582                                        if ($sponsor_info != null) 
    515583                                        { 
     
    532600                                        } 
    533601                                } 
     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                                } 
    534642 
    535643                        } 
    536644        } 
    537  
    538645        /** Subscribe to the project  
    539646         * @return true on success, false on failure */ 
     
    550657                return false; 
    551658        } 
    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 */ 
    555662        public function isPersistent() 
    556663        { 
    557                 if($this->content_row['is_persistent']=='t') 
     664                if ($this->content_row['is_persistent'] == 't') 
    558665                { 
    559666                        $retval = true; 
     
    561668                else 
    562669                { 
    563                         $retval=false; 
     670                        $retval = false; 
    564671                } 
    565672                return $retval; 
    566673        } 
    567          
     674 
    568675        /** Set if the content group is persistent 
    569676         * @param $is_locative_content true or false 
     
    571678        public function setIsPersistent($is_persistent) 
    572679        { 
    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 operation 
    585          * @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        { 
    588695                $this->__construct($this->id); 
    589696        } 
    590          
     697 
    591698        /** Delete this Content from the database  
    592699         * @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); 
    600711                } 
    601712        } 
  • trunk/wifidog-auth/wifidog/classes/Content/ContentGroup.php

    r550 r551  
    179179                        } 
    180180                                                $html .= "<li class='admin_section_list_item'>\n"; 
    181                                                 $html .= self :: getNewContentInterface("content_group_{$this->id}_new_element"); 
     181                                                $html .= self :: getNewContentUI("content_group_{$this->id}_new_element"); 
    182182                                                                                $html .= "</li>\n"; 
    183183                $html .= "</ul>\n"; 
     
    216216                        } 
    217217 
    218 /* We explicitely call the ContentGroupElement version of processNewContentInterface */ 
    219                 $new_element = ContentGroupElement :: processNewContentInterface("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); 
    220220        } 
    221221        /**Get all elements 
  • trunk/wifidog-auth/wifidog/classes/Content/ContentGroupElement.php

    r550 r551  
    3232        private $content_group_element_row; 
    3333 
    34         /** Thelike the same class as defined in Content, this methos will create a ContentGroupElement based on the content type specified by getNewContentInterface 
     34        /** Like the same method as defined in Content, this method will create a ContentGroupElement based on the content type specified by getNewContentUI 
    3535         * @param $user_prefix A identifier provided by the programmer to recognise it's generated form 
    3636         * @param $content_group Must be present 
    3737         * @return the ContentGroup object, or null if the user didn't greate one 
    3838         */ 
    39         static function processNewContentInterface($user_prefix, ContentGroup $content_group) 
     39        static function processNewContentUI($user_prefix, ContentGroup $content_group) 
    4040        { 
    4141                global $db; 
     
    5050 
    5151                        $name = "get_new_content_{$user_prefix}_content_type"; 
    52                         $content_type = FormSelectGenerator :: getResult($name, null); 
    53                         $displayed_content_object = self :: createNewContent($content_type); 
    5452 
    5553                        $content_id = get_guid(); 
     
    6765                        } 
    6866                        $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); 
    6972                        $content_group_element_object->replaceDisplayedContent($displayed_content_object); 
     73                        } 
    7074                } 
    7175                return $content_group_element_object; 
     
    8488                if ($row == null) 
    8589                { 
    86                         $db->ExecSqlUniqueRes($sql_select, $row, false); 
    87                         if ($row == null) 
    88                         { 
    8990                                throw new Exception(_("The content with the following id could not be found in the database: ").$content_id); 
    90                         } 
    91  
    9291                } 
    9392                $this->content_group_element_row = $row; 
     
    164163                if (empty ($this->content_group_element_row['displayed_content_id'])) 
    165164                { 
    166                         $html .= self :: getNewContentInterface("content_group_element_{$this->id}_new_displayed_content"); 
     165                        $html .= self :: getNewContentUI("content_group_element_{$this->id}_new_displayed_content"); 
    167166                } 
    168167                else 
     
    248247                if (empty ($this->content_group_element_row['displayed_content_id'])) 
    249248                { 
    250                         $displayed_content = Content :: processNewContentInterface("content_group_element_{$this->id}_new_displayed_content"); 
     249                        $displayed_content = Content :: processNewContentUI("content_group_element_{$this->id}_new_displayed_content"); 
    251250                        if ($displayed_content != null) 
    252251                        { 
     
    291290        } 
    292291 
     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         
    293301        /** Delete this Content from the database  
    294302         * @todo Implement proper Access control */ 
  • trunk/wifidog-auth/wifidog/classes/Content/Langstring.php

    r550 r551  
    3131error_reporting(E_ALL); 
    3232 
    33 /** Représente un Langstring en particulier, ne créez pas un objet langstrings si wous n'en avez pas spécifiquement besoin  
     33/** Représente un Langstring en particulier, ne créez pas un objet langstrings si vous n'en avez pas spécifiquement besoin  
    3434 */ 
    3535class Langstring extends Content 
     
    5454 
    5555                $sql = "SELECT value, locales_id, \n"; 
    56                 $sql .= Locale :: getSqlCaseStringSelect(User :: getCurrentUser()->getPreferedLocale()); 
     56                $sql .= Locale :: getSqlCaseStringSelect(LocaleList::GetDefault()); 
    5757                $sql .= " as score FROM langstring_entries WHERE langstring_entries.langstrings_id = '{$this->id}' ORDER BY score LIMIT 1"; 
    5858                $this->mBd->ExecSqlUniqueRes($sql, $row, false); 
     
    169169 
    170170                //Nouvelles chaîne 
    171                 $locale = User :: getCurrentUser()->getPreferedLocale(); 
     171                $locale =  LocaleList::GetDefault(); 
    172172                $html .= "<li class='admin_section_list_item'>\n"; 
    173173                $html .= $liste_languages->GenererFormSelect($locale, "langstrings_".$this->id."_substring_new_language", 'Langstring::AfficherInterfaceAdmin', TRUE); 
  • trunk/wifidog-auth/wifidog/classes/LocaleList.php

    r545 r551  
    11<?php 
     2 
    23/********************************************************************\ 
    34 * This program is free software; you can redistribute it and/or    * 
     
    4041        { 
    4142                //parent::__construct(); 
    42                                 global $db; 
    43                 $this->mBd=&$db;//for backward compatibility 
     43                global $db; 
     44                $this->mBd = & $db; //for backward compatibility 
    4445        } 
    4546 
     
    6364                $retval = ""; 
    6465                $sql = "SELECT * FROM locales ORDER BY locales_id"; 
    65                 $this -> mBd -> ExecSql($sql, $resultats, FALSE); 
     66                $this->mBd->ExecSql($sql, $resultats, FALSE); 
    6667 
    6768                $retval = ""; 
    68                 $retval.= "<select name='$prefixeNomSelectUsager$prefixeNomSelectObjet'>\n"; 
     69                $retval .= "<select name='$prefixeNomSelectUsager$prefixeNomSelectObjet'>\n"; 
    6970                if ($permetValeurNulle == true) 
    7071                { 
    71                         $retval.= "<option value=''>---</option>\n"; 
     72                        $retval .= "<option value=''>---</option>\n"; 
    7273                } 
    7374                //echo "$selectedClefPrimaire"; 
    7475                while (list ($key, $value) = each($resultats)) 
    7576                { 
    76                         $retval.= "<option "; 
     77                        $retval .= "<option "; 
    7778 
    7879                        //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()) 
    8081                        { 
    81                                 $retval.= "SELECTED "; 
     82                                $retval .= "SELECTED "; 
    8283                        } 
    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"; 
    8586                } 
    86                 $retval.= "</select>\n"; 
     87                $retval .= "</select>\n"; 
    8788                return $retval; 
    8889        } 
    89  
    90  
    9190 
    9291        /**Retourne le language par défaut, selon les préférences de l'usager 
    9392        */ 
    9493        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; 
    98110        } 
    99          
     111 
    100112        /**Retourne la liste de toutes les clef primairess 
    101113        */ 
    102114        function GetListeClefsPrimaires() 
    103115        { 
    104                 $this -> mBd -> ExecuterSql("SELECT locales_id FROM locales", $resultats, FALSE); 
     116                $this->mBd->ExecuterSql("SELECT locales_id FROM locales", $resultats, FALSE); 
    105117 
    106118                foreach ($resultats as $resultat) 
    107119                { 
    108                         $retval[]=$resultat['locales_id']; 
     120                        $retval[] = $resultat['locales_id']; 
    109121                } 
    110122                return $retval; 
     
    117129        @param $entree ID de l'entree de vocabulaire 
    118130        */ 
    119         function Export($export_format, &$document, $parent, $entree = null) 
    120         {                                
     131        function Export($export_format, & $document, $parent, $entree = null) 
     132        { 
    121133                if ($entree != null) 
    122134                { 
    123135                        $langue = new Locale($entree); 
    124                         $langue -> Export($export_format, $document, $parent); 
     136                        $langue->Export($export_format, $document, $parent); 
    125137                } 
    126138        } 
    127          
     139 
    128140        function isEmpty() 
    129141        { 
    130142                return false; 
    131143        } 
    132          
     144 
    133145        /** 
    134146         * By definition it cannot be considerend empty, so it's always compliant' 
     
    139151                return COMPLIANT_MASK; 
    140152        } 
    141          
     153 
    142154} /* end class LocaleList */ 
    143155?> 
     156 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r545 r551  
    11<?php 
     2 
    23/********************************************************************\ 
    34 * This program is free software; you can redistribute it and/or    * 
     
    2425 
    2526require_once BASEPATH.'include/common.php'; 
    26  
     27require_once BASEPATH.'classes/Network.php'; 
    2728/** Abstract a User. */ 
    2829class User 
     
    4142                return $object; 
    4243        } 
    43          
     44 
    4445        /** Instantiate the current user 
    4546         * @return a User object, or null if there was an error 
     
    4950                require_once BASEPATH.'classes/Session.php'; 
    5051                $session = new Session(); 
    51                 $user=null; 
     52                $user = null; 
    5253                try 
    5354                { 
    5455                        $user = new User($session->get(SESS_USER_ID_VAR)); 
    5556                } 
    56                 catch(Exception $e) 
     57                catch (Exception $e) 
    5758                { 
    5859                        /**If any problem occurs, the user should be considered logged out*/ 
     
    6162                return $user; 
    6263        } 
    63          
     64 
    6465        /** Instantiate a user object  
    6566         * @param $username The username of the user 
     
    7677                $db->ExecSqlUniqueRes("SELECT user_id FROM users WHERE username = '$username_str' AND account_origin = '$account_origin_str'", $user_info, false); 
    7778 
    78                 if($user_info != null) 
     79                if ($user_info != null) 
    7980                        $object = new self($user_info['user_id']); 
    8081                return $object; 
    8182        } 
    82          
     83 
    8384        /** Instantiate a user object  
    8485         * @param $email The email of the user 
     
    9596                $db->ExecSqlUniqueRes("SELECT user_id FROM users WHERE email = '$email_str' AND account_origin = '$account_origin_str'", $user_info, false); 
    9697 
    97                 if($user_info != null) 
     98                if ($user_info != null) 
    9899                        $object = new self($user_info['user_id']); 
    99100                return $object; 
     
    216217                $email_str = $db->EscapeString($email); 
    217218                /** 
    218         * utf8_decode is used for backward compatibility with old passwords 
    219         * containing special characters.  
    220         * Conversion from UTF-8 to ISO-8859-1 is done to match the MD5 hash 
    221         */ 
     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                */ 
    222223                $password_hash = $db->EscapeString(User :: passwordHash(utf8_decode($password))); 
    223224                $status = ACCOUNT_STATUS_VALIDATION; 
     
    239240                if ($row == null) 
    240241                { 
    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")); 
    242243                } 
    243244                $this->mRow = $row; 
     
    250251        } 
    251252 
     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 
    252261        function getUsername() 
    253262        { 
     
    260269        } 
    261270 
    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 */ 
    264273        public function getPreferedLocale() 
    265274        { 
     
    267276                //return $this->mRow['prefered_locale']; 
    268277                $locale = $session->get('SESS_LANGUAGE_VAR'); 
    269                 if(empty($locale)) 
    270                 { 
    271                         $locale=DEFAULT_LANG; 
     278                if (empty ($locale)) 
     279                { 
     280                        $locale = DEFAULT_LANG; 
    272281                } 
    273282                return $locale; 
     
    303312        function isUserValid(& $errmsg = null) 
    304313        { 
    305         global $db; 
     314                global $db; 
    306315                $retval = false; 
    307316                $account_status = $this->getAccountStatus(); 
     
    377386        { 
    378387                global $db; 
    379                  
     388 
    380389                $new_password_hash = User :: passwordHash(utf8_decode($password)); 
    381390                if (!($update = $db->ExecSqlUpdate("UPDATE users SET pass='$new_password_hash' WHERE user_id='{$this->mId}'"))) 
     
    410419        { 
    411420                $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"; 
    414423                $headers .= "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 
    415424                $subject = HOTSPOT_NETWORK_NAME._(" lost username request"); 
    416425                $body = _("Hello,\nYou have requested that the authentication server send you your username:\nUsername: ").$username._("\n\nHave a nice day,\nThe Team"); 
    417                  
     426 
    418427                mail($this->getEmail(), $subject, $body, $headers); 
    419428        } 
     
    433442                        else 
    434443                        { 
    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"; 
    437446                                $headers .= "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 
    438447                                $subject = HOTSPOT_NETWORK_NAME._(" new user validation"); 
    439448                                $url = "http://".$_SERVER["SERVER_NAME"]."/validate.php?user_id=".$this->getId()."&token=".$this->getValidationToken(); 
    440449                                $body = _("Hello,\nPlease follow the link below to validate your account.\n").$url._("\n\nThank you,\nThe Team."); 
    441                                  
     450 
    442451                                mail($this->getEmail(), $subject, $body, $headers); 
    443452                        } 
     
    452461                $this->setPassword($new_password); 
    453462                $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"; 
    457466                $headers .= "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 
    458467                $subject = HOTSPOT_NETWORK_NAME._(" new password request"); 
    459468                $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 
    461470                mail($this->getEmail(), $subject, $body, $headers); 
    462471        } 
     
    471480        } 
    472481 
    473         function emailExists($id) 
     482        public static function emailExists($id) 
    474483        { 
    475484                global $db; 
     
    510519        } 
    511520 
     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 
    512549} // End class 
    513550?> 
     551