source: bureau/class/m_admin.php @ 787

Revision 787, 24.1 KB checked in by anarcat, 7 years ago (diff)

[project @ alternc: changeset 2005-12-17 17:21:56 by benjamin]
ajout fonction permettant de locker et delocker un username,
correction

Original author: benjamin
Date: 2005-12-17 17:21:56

Line 
1<?php
2/*
3 $Id: m_admin.php,v 1.13 2005/12/17 17:21:56 benjamin Exp $
4 ----------------------------------------------------------------------
5 LICENSE
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License (GPL)
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 To read the license please visit http://www.gnu.org/copyleft/gpl.html
18 ----------------------------------------------------------------------
19 Original Author of file: Benjamin Sonntag
20 Purpose of file: Administrate members and rights.
21 ----------------------------------------------------------------------
22*/
23/* ----------------------------------------------------------------- */
24/**
25* Classe de gestion de l'administration du serveur par les super-admin.
26*
27* Cette classe permet de créer / modifier / détruire les comptes, ainsi que de
28* modifier les paramètres du serveur.<br />
29* Copyleft {@link http://alternc.net/ AlternC Team}
30*
31*
32*/
33class m_admin {
34
35  /* ----------------------------------------------------------------- */
36  /**
37   * $enabled precises if the logged user is super-admin or not
38   */
39  var $enabled=0;
40
41  /* ----------------------------------------------------------------- */
42    /** List of the controls made for each TLD
43    *
44    * $tldmode is used by the administration panel, while choosing
45    * the authorized TLDs. It's an array of strings explaining the current state of the TLD.
46    */
47
48  var $tldmode=array(
49                     0 => "This TLD is forbidden",
50                     1 => "primary DNS is checked in WHOIS db",
51                     2 => "primary & secondary DNS are checked in WHOIS db",
52                     3 => "Domain must exist, but don't do any DNS check",
53                     4 => "Domain can be installed, no check at all",
54                     5 => "Domain can be installed, force NO DNS hosting"
55                     );
56
57  /* ----------------------------------------------------------------- */
58  /**
59   * Constructeur
60   */
61  function m_admin() {
62    global $db,$cuid;
63    $db->query("SELECT su FROM membres WHERE uid='$cuid';");
64    $db->next_record();
65    $this->enabled=$db->f("su");
66  }
67
68  /* ----------------------------------------------------------------- */
69  /**
70   * Returns the known information about a hosted account
71   *
72   * Returns all what we know about an account (contents of the tables
73   *  <code>membres</code> et <code>local</code>)
74   * Ckecks if the account is super-admin
75   * @param integer $uid a unique integer identifying the account
76   * @return an associative array containing all the fields of the
77   * table <code>membres</code> and <code>local</code> of the corresponding account.
78   * Returns FALSE if an error occurs.
79   *
80   * Retourne tout ce que l'on sait sur un membre (contenu des tables <code>membres et local</code>)
81   * vérifie que le compte appelant est super-admin
82   * @param integer $uid Numéro de l'utilisateur dont on veut les informations.
83   * @return array Retourne un tableau associatif contenant l'ensemble des champs des tables 'membres'
84   *  et 'local' pour le membre demandé. Retourne FALSE si une erreur s'est produite.
85   *
86   */
87  function get($uid) {
88    global $err,$db;
89    //    $err->log("admin","get",$uid);
90    if (!$this->enabled) {
91      $err->raise("admin",1);
92      return false;
93    }
94    $db->query("SELECT * FROM membres WHERE uid='$uid';");
95    if ($db->num_rows()) {
96      $db->next_record();
97      $c=$db->Record;
98    } else {
99      $err->raise("admin",2);
100      return false;
101    }
102    $db->query("SELECT * FROM local WHERE uid='$uid';");
103    if ($db->num_rows()) {
104      $db->next_record();
105      reset($db->Record);
106      while (list($key,$val)=each($db->Record)) {
107        $c[$key]=$val;
108      }
109    }
110    return $c;
111  }
112
113  /* ----------------------------------------------------------------- */
114  /**
115   * @return TRUE if there's only ONE admin account
116   * Retourne true s'il n'existe qu'un seul compte administrateur
117   */
118  function onesu() {
119    global $db;
120    $db->query("SELECT COUNT(*) AS cnt FROM membres WHERE su=1");
121    $db->next_record();
122    return ($db->f("cnt")==1);
123  }
124
125  /* ----------------------------------------------------------------- */
126  /**
127   * Returns the list of the hosted accounts
128   * Retourne la liste des membres hébergés
129   *
130   * Returns all what we know about ALL the accounts (contents of the tables
131   *  <code>membres</code> et <code>local</code>)
132   * Check for super-admin accounts
133   * @param
134   * @return an associative array containing all the fields of the
135   * table <code>membres</code> and <code>local</code> of all the accounts.
136   * Returns FALSE if an error occurs.
137   *
138   * Retourne tout ce que l'on sait sur LES membres (contenu de membres et local)
139   * vérifie que le compte appelant est super-admin
140   * @return array Retourne un tableau indexé de tableaux associatifs contenant l'ensemble des
141   *  champs des tables 'membres' et 'local' pour les membre. Retourne FALSE si une erreur s'est
142   *  produite.
143   *
144   */
145  function get_list($all=0) {
146    // PATCHBEN pour ne voir que les comptes que l'on a créé (sauf root)
147    global $err,$mem,$cuid;
148    $err->log("admin","get_list");
149    if (!$this->enabled) {
150      $err->raise("admin",1);
151      return false;
152    }
153    $db=new DB_System();
154    if ($mem->user[uid]==2000 || $all) {
155      $db->query("SELECT uid FROM membres ORDER BY login;");
156    } else {
157      $db->query("SELECT uid FROM membres WHERE creator='".$cuid."' ORDER BY login;");
158    }
159    if ($db->num_rows()) {
160      while ($db->next_record()) {
161        $c[]=$this->get($db->f("uid"));
162      }
163      return $c;
164    } else {
165      $err->raise("admin",3);
166      return false;
167    }
168  }
169
170  /* ----------------------------------------------------------------- */
171  /**
172   * Check if I am the creator of the member $uid
173   *
174   * @param integer $uid a unique integer identifying the account
175   */
176  function checkcreator($uid) {
177    global $err,$mem,$db,$cuid;
178    // DONE PATCHBEN Check that the current user is editing one of it's own account !
179    // but ROOT (always uid 2000) is almighty
180    if ($cuid==2000) {
181      return true;
182    }
183    $db->query("SELECT creator FROM membres WHERE uid='$uid';");
184    $db->next_record();
185    if ($db->Record[creator]!=$cuid) {
186      $err->raise("admin",1);
187      return false;
188    }
189    return true;
190  }
191
192  /* ----------------------------------------------------------------- */
193  /**
194   * Creates a new hosted account
195   * 
196   * Creates a new hosted account (in the tables <code>membres</code>
197   * and <code>local</code>). Prevents any manipulation of the account if
198   * the account $mid is not super-admin.
199   *
200   * @param $login string Login name like [a-z][a-z0-9]*
201   * @param $pass string Password (max. 64 characters)
202   * @param $nom string Name of the account owner
203   * @param $prenom string First name of the account owner
204   * @param $mail string Email address of the account owner, useful to get
205   * one's lost password
206   * @return boolean Returns FALSE if an error occurs, TRUE if not.
207   *
208   *
209   * Crée un nouveau membre hébergé
210   * Création d'un nouveau membre (dans membres et local) Refuse l'utilisation de l'objet
211   * si le compte $mid n'est pas super-admin
212   *
213   * @param $login Nom d'utilisateur, de la forme [a-z][a-z0-9]*
214   * @param $pass Mot de passe, maxi 64 caractères
215   * @param $nom Nom de la personne ou structure
216   * @param $prenom Prénom de la personne ou structure
217   * @param $mail Adresse email du propriétaire du compte, permet de récupérer son mot de passe
218   * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
219   *
220   */
221  function add_mem($login, $pass, $nom, $prenom, $mail, $canpass=1) {
222    global $err,$quota,$classes,$cuid,$mem,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN;
223    $err->log("admin","add_mem",$login."/".$mail);
224    if (!$this->enabled) {
225      $err->raise("admin",1);
226      return false;
227    }
228    if (($login=="")||($pass=="")||($mail=="")){
229      $err->raise("admin",6);
230      return false;
231    }
232    if (checkmail($mail)!=0){
233      $err->raise("admin",5);
234      return false;
235    }
236    // Vérification de la conformité du login
237    $login=strtolower($login);
238    if (!ereg("^[a-z0-9]*$",$login)) { //$
239      $err->raise("admin",10);
240      return false;
241    }
242    if (strlen($login) > 60) {
243      $err->raise("admin",13);
244      return false;
245    }
246    // Il ne peut pas être égal au login ou au nom de base systeme !
247    if ($login==$L_MYSQL_DATABASE || $login==$L_MYSQL_LOGIN) {
248      $err->raise("admin",10);
249      return false;
250    }
251    $pass=_md5cr($pass);
252    $db=new DB_System();
253    // vérification de l'inexistence du membre dans system.membres
254    $db->query("SELECT count(*) AS cnt FROM membres WHERE login='$login';");
255    $db->next_record();
256    if (!$db->f("cnt")) {
257      $db->query("SELECT m.uid+1 as nextid FROM membres m LEFT JOIN membres n ON m.uid=n.uid-1 WHERE n.uid IS NULL ORDER BY 1 LIMIT 0,1");
258      if (!$db->next_record()) {
259        $uid=2000;
260      } else {
261        $uid=$db->Record["nextid"];
262        if ($uid<=2000) $uid=2000;
263      }
264      // on le créé ensuite dans system.membres et system.local
265      $db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass) VALUES ('$uid','$login','$pass','$mail','$cuid','$canpass');");
266      $db->query("INSERT INTO local(uid,nom,prenom) VALUES('$uid','$nom','$prenom');");
267      exec("/usr/lib/alternc/mem_add ".$login." ".$uid);
268      // Declenchons les autres classes.
269      $mem->su($uid);
270      for($i=0;$i<count($classes);$i++) {
271        if (method_exists($GLOBALS[$classes[$i]],"alternc_add_member")) {
272          $GLOBALS[$classes[$i]]->alternc_add_member();
273        }
274      }
275      $mem->unsu();
276      return $uid;
277    } else {
278      $err->raise("admin",3);
279      return false;
280    }
281  }
282
283  /* ----------------------------------------------------------------- */
284  /**
285   * Modifies an account
286   * 
287   * Modifies an account (in the tables <code>membres</code>
288   * and <code>local</code>). Prevents any manipulation of the account if
289   * the account $mid is not super-admin.
290   *
291   * @param $uid integer the uid number of the account we want to modify
292   * @param login string new login name like [a-z][a-z0-9]*
293   * @param $pass string new password (max. 64 characters)
294   * @param $nom string new name of the account owner
295   * @param $prenom string new first name of the account owner
296   * @param $mail string new email address of the account owner
297   * @param $enabled integer (value: 0 or 1) activates or desactivates the
298   * access to the virtual desktop of this account.
299   * @return boolean Returns FALSE if an error occurs, TRUE if not.
300   *
301   * Modifie un membre hébergé
302   *
303   * modifie les données d'un membre. Refuse l'utilisation de l'objet
304   * si le compte $mid n'est pas super-admin
305   *
306   * @param $uid integer Numéro uid de l'utilisateur que l'on souhaite modifier.
307   * @param $mail string Nouvelle adresse email
308   * @param $nom $prenom string Nouveaux nom et prénom de l'utilisateur
309   * @param $pass string Nouveau mot de passe.
310   * @param $enabled integer vaut 0 ou 1, active ou désactive l'accès au bureau virtuel de ce compte.
311   * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
312   *
313   */
314  function update_mem($uid, $mail, $nom, $prenom, $pass, $enabled,$canpass) {
315    global $err,$db;
316    $err->log("admin","update_mem",$uid);
317    if (!$this->enabled) {
318      $err->raise("admin",1);
319      return false;
320    }
321    $db=new DB_System();
322    if ($pass) {
323      // on modifie aussi le password :
324      $pass=_md5cr($pass);
325      $ssq=" ,pass='$pass' ";
326    } else {
327      $ssq="";
328    }
329    if (($db->query("UPDATE local SET nom='$nom', prenom='$prenom' WHERE uid='$uid';"))
330        &&($db->query("UPDATE membres SET mail='$mail', canpass='$canpass', enabled='$enabled' $ssq WHERE uid='$uid';"))){
331      return true;
332    }
333    else {
334      $err->raise("admin",2);
335      return false;
336    }
337  }
338
339  /* ----------------------------------------------------------------- */
340  /**
341   * Lock an account
342   *
343   * Lock an account and prevent the user to access its account.
344   *
345   * @param $uid integer the uid number of the account we want to lock
346   * @return boolean Returns FALSE if an error occurs, TRUE if not.
347   */
348  function lock_mem($uid) {
349    global $err,$db;
350    $err->log("admin","lock_mem",$uid);
351    if (!$this->enabled) {
352      $err->raise("admin",1);
353      return false;
354    }
355    $db=new DB_System();
356    if ($db->query("UPDATE membres SET enabled='0' WHERE uid='$uid';")) {
357      return true;
358    }
359    else {
360      $err->raise("admin",2);
361      return false;
362    }
363  }
364
365
366  /* ----------------------------------------------------------------- */
367  /**
368   * UnLock an account
369   *
370   * UnLock an account and prevent the user to access its account.
371   *
372   * @param $uid integer the uid number of the account we want to unlock
373   * @return boolean Returns FALSE if an error occurs, TRUE if not.
374   */
375  function unlock_mem($uid) {
376    global $err,$db;
377    $err->log("admin","unlock_mem",$uid);
378    if (!$this->enabled) {
379      $err->raise("admin",1);
380      return false;
381    }
382    $db=new DB_System();
383    if ($db->query("UPDATE membres SET enabled='1' WHERE uid='$uid';")) {
384      return true;
385    }
386    else {
387      $err->raise("admin",2);
388      return false;
389    }
390  }
391
392
393
394  /* ----------------------------------------------------------------- */
395  /**
396   * Deletes an account
397   *
398   * Deletes the specified account. Prevents any manipulation of the account if
399   * the account $mid is not super-admin.
400   *
401   * @param $uid integer the uid number of the account we want to delete
402   * @return boolean Returns FALSE if an error occurs, TRUE if not.
403   *
404   *
405   * Efface un membre hébergé
406   *
407   * Supprime le membre spécifié. Refuse l'utilisation de l'objet si le compte $mid n'est pas super-admin
408   * @param $uid Numéro du membre à supprimer.
409   * @return Retourne FALSE si une erreur s'est produite, TRUE sinon.
410   *
411   */
412  function del_mem($uid) {
413    global $err,$quota,$classes,$cuid,$mem,$dom;
414    $err->log("admin","del_mem",$uid);
415
416    if (!$this->enabled) {
417      $err->raise("admin",1);
418      return false;
419    }
420    $db=new DB_System();
421    $tt=$this->get($uid);
422   
423    // On devient l'utilisateur :
424    $mem->su($uid);
425
426    // WE MUST call m_dom before all others because of conflicts ...
427    $dom->alternc_del_member();
428
429      // Send the event to the other classes :
430      for($i=0;$i<count($classes);$i++) {
431        if (method_exists($GLOBALS[$classes[$i]],"alternc_del_member") && $classes[$i]!="dom") {
432          $GLOBALS[$classes[$i]]->alternc_del_member();
433        }
434      }
435    if (($db->query("DELETE FROM membres WHERE uid='$uid';")) &&
436        ($db->query("DELETE FROM local WHERE uid='$uid';"))) {
437      exec("/usr/lib/alternc/mem_del ".$tt["login"]);
438      $mem->unsu();
439      return true;
440    } else {
441      $err->raise("admin",2);
442      $mem->unsu();
443      return false;
444    }
445  }
446
447  /* ----------------------------------------------------------------- */
448  /**
449   * Turns a common account into a super-admin account
450   *
451   * @param $uid integer the uid number of the common account we want to turn into a
452   *  super-admin account.
453   * @return Returns FALSE if an error occurs, TRUE if not.
454   *
455   *
456   * Transforme un membre Normal en membre Administrateur
457   *
458   * @param $uid Numéro du compte à transformer
459   * @return Retourne FALSE si une erreur s'est produite.
460   *
461   */
462  function normal2su($uid) {
463    global $err,$db;
464    $db->query("SELECT su FROM membres WHERE uid='$uid';");
465    if (!$db->next_record()) {
466      $err->raise("admin",2);
467      return false;
468    } 
469    if ($db->Record["su"]!=0) {
470      $err->raise("admin",8);
471      return false;
472    }
473    $db->query("UPDATE membres SET su=1 WHERE uid='$uid';");
474    return true;
475  }
476
477  /* ----------------------------------------------------------------- */
478  /**
479   * Turns a super-admin account into a common account
480   *
481   * @param $uid integer the uid number of the super-admin account we want to turn into a
482   * common account.
483   * @return boolean Returns FALSE if an error occurs, TRUE if not.
484   *
485   *
486   * Transforme un membre Administrateur en membre Normal
487   * @param integer $uid Numéro du compte à transformer
488   * @return boolean Retourne FALSE si une erreur s'est produite.
489   *
490   */
491  function su2normal($uid) {
492    global $err,$db;
493    $db->query("SELECT su FROM membres WHERE uid='$uid';");
494    if (!$db->next_record()) {
495      $err->raise("admin",2);
496      return false;
497    }
498    if ($db->Record["su"]!=1) {
499      $err->raise("admin",9);
500      return false;
501    }
502    $db->query("UPDATE membres SET su=0 WHERE uid='$uid';");
503    return true;
504  }
505
506  /* ----------------------------------------------------------------- */
507  /**
508   * List of the authorized TLDs
509   *
510   * Returns the list of the authorized TLDs and also the way they are
511   * authorized. A TLD is the last members (or the last two) of a
512   * domain. For example, "com", "org" etc... AlternC keeps a table
513   * containing the list of the TLDs authorized to be installed on the
514   * server with the instructions to validate the installation of a
515   * domain for each TLD (if necessary).
516   *
517   * @return array An associative array like $r["tld"], $r["mode"] where tld
518   * is the tld and mode is the authorized mode.
519   *
520   *
521   * Liste des TLD autorisés
522   *
523   * Retourne la liste des tld autorisés, ainsi que la façon dont ils sont autorisés.
524   * Les tld sont le dernier membre (ou parfois les 2 derniers membres) d'un domaine.
525   * Par exemple "org" "com" etc. AlternC conserve une table "tld" qui contient la liste
526   * des TLD autorisés à être installé sur le serveur, accompagné des vérifications à effectuer
527   * pour chaque TLD. Par exemple, on peux vérifier que les DNS du domaine pointent bien vers
528   * notre serveur, ou juste que le domaine existe etc.
529   * <p><b>Note</b> : Il faudrait pouvoir effectuer une requete DNS, et pouvoir juste vérifier les DNS
530   * via DIG et pas seulement via Whois</p>
531   *
532   * @return array Retourne un tableau de tableau associatif du type $r["tld"], $r["mode"].
533   *  TLD est le tld et MODE est le mode autorisé
534   *
535   */
536  function listtld() {
537    global $db;
538    $db->query("SELECT tld,mode FROM tld ORDER BY tld;");
539    while ($db->next_record()) {
540      $c[]=$db->Record;
541    }
542    return $c;
543  }
544
545  /* ----------------------------------------------------------------- */
546  /**
547   * List the hosted domains on this server
548   *
549   * Return the list of hosted domains on this server, (an array of associative arrays)
550   * @return array $r[$i] / [domaine][member][noerase][gesdns][gesmx]
551   */
552  function dom_list() {
553    global $db;
554    $db->query("SELECT m.login,d.domaine,d.gesdns,d.gesmx,d.noerase FROM domaines d LEFT JOIN membres m ON m.uid=d.compte ORDER BY domaine;");
555    while ($db->next_record()) {
556      $c[]=$db->Record;
557    }
558    return $c;
559  }
560
561  /* ----------------------------------------------------------------- */
562  /**
563   * Lock / Unlock a domain
564   *
565   * Lock (or unlock) a domain, so that the member will be (not be) able to delete it
566   * from its account
567   * @param $dom string Domain name to lock / unlock
568   * @return boolean TRUE if the domain has been locked/unlocked or FALSE if it does not exist.
569   */
570  function dom_lock($domain) {
571    global $db,$err;
572    $db->query("SELECT compte FROM domaines WHERE domaine='$domain';");
573    if (!$db->next_record()) {
574      $err->raise("dom",1);
575      return false;
576    }
577    $db->query("UPDATE domaines SET noerase=1-noerase WHERE domaine='$domain';");
578    return true;
579  }
580
581
582  /* ----------------------------------------------------------------- */
583  /**
584   * Add a new TLD to the list of the authorized TLDs
585   *
586   * @param $tld string top-level domain to add (org, com...)
587   * @param $mode integer number of the authorized mode (0 to 5)
588   * @return boolean TRUE if the tld has been successfully added, FALSE if not.
589   *
590   *
591   * Ajoute un nouveau TLD autorisé à la liste des tld autorisés.
592   *
593   * @param $tld Top-Level Domain à ajouter (org, com ...)
594   * @param $mode Numéro du mode autorisé (0->5)
595   * @return boolean True si le tld a bien été ajouté, False sinon.
596   *
597   */ 
598  function gettld($tld) {
599    global $db,$err;
600    $db->query("SELECT mode FROM tld WHERE tld='$tld';");
601    if (!$db->next_record()) {
602      $err->raise("admin",11);
603      return false;
604    }
605    return $db->Record["mode"];
606  }
607
608  /* ----------------------------------------------------------------- */
609  /**
610   * Prints the list of the actually authorized TLDs
611   *
612   * @param $current integer Value to select in the list
613   *
614   * Affiche (echo) la liste déroulante des TLD actuellement autorisés.
615   *
616   * @param $current Valeur par défaut à sélectionner dans la liste
617   *
618   */
619  function selecttldmode($current=false) {
620    for($i=0;$i<count($this->tldmode);$i++) {
621      echo "<option value=\"$i\"";
622      if ($current==$i) echo " selected=\"selected\"";
623      echo ">"._($this->tldmode[$i])."</option>\n";
624    }
625  }
626
627  /* ----------------------------------------------------------------- */
628  /**
629   * Deletes the specified tld in the list of the authorized TLDs
630   * <b>Note</b> : This function does not delete the domains depending
631   * on this TLD
632   *
633   * @param $tld string The TLD you want to delete
634   * @return boolean returns true if the TLD has been deleted, or
635   * false if an error occured.
636   *
637   *
638   * Supprime le tld indiqué de la liste des TLD autorisés à l'installation
639   *
640   * <b>Note</b> : Cela ne supprime pas les domaines utilisant ce TLD !
641   *
642   * @param $tld TLD que l'on souhaite détruire
643   * @return boolean retourne true si le TLD a bien été effacé, false sinon
644   *
645   */
646  function deltld($tld) {
647    global $db,$err;
648    $db->query("SELECT tld FROM tld WHERE tld='$tld';");
649    if (!$db->next_record()) {
650      $err->raise("admin",11);
651      return false;
652    }
653    $db->query("DELETE FROM tld WHERE tld='$tld';");
654    return true;
655  }
656
657  /* ----------------------------------------------------------------- */
658  /**
659   * Add a TLD to the list of the authorized TLDs during the
660   * installation
661   *
662   * @param $tld string TLD we want to authorize
663   * @param $mode integer Controls to make on this TLD.
664   * <b>Note: </b> If you check in the whois, be sure that
665   *  <code>m_domains</code> knows how to name the whois of the specified
666   *  domain !
667   * @return boolean TRUE if the TLD has been successfully
668   *  added. FALSE if not.
669   *
670   *
671   *
672   * Ajoute un TLD à la liste des TLD autorisés à l'installation
673   *
674   * @param $tld TLD que l'on souhaite autoriser.
675   * @param $mode Contrôles à effectuer sur ce TLD. <b>Note : </b>
676   *  Si vous demandez le controle dans le Whois, assurez-vous que m_domains
677   *  connaisse bien comment appeler le whois du domaine correspondant !
678   * @return boolean retourne true si le TLD a bien été ajouté, false sinon
679   *
680   */
681  function addtld($tld,$mode) {
682    global $db,$err;
683    if (!$tld) {
684      $err->raise("admin",12);
685      return false;
686    }
687    $db->query("SELECT tld FROM tld WHERE tld='$tld';");
688    if ($db->next_record()) {
689      $err->raise("admin",12);
690      return false;
691    }
692    if (substr($tld,0,1)==".") $tld=substr($tld,1);
693    $mode=intval($mode);
694    if ($mode==0) $mode="0";
695    $db->query("INSERT INTO tld (tld,mode) VALUES ('$tld','$mode');");
696    return true;
697  }
698
699  /* ----------------------------------------------------------------- */
700  /**
701   * Modify a TLD of the list of the authorized TLDs
702   *
703   * @param $tld string TLD we want to modify
704   * @param $mode integer Controls to make on this TLD.
705   * @return boolean TRUE if the TLD has been successfully
706   * modified. FALSE if not.
707   *
708   *
709   * Modifie un TLD autorisé de la liste des tld autorisés.
710   *
711   * @param $tld Top-Level Domain à modifier (org, com ...)
712   * @param $mode Numéro du mode autorisé (0->5)
713   * @return boolean True si le tld a bien été modifié, False sinon.
714   *
715   */
716  function edittld($tld,$mode) {
717    global $db,$err;
718    $db->query("SELECT tld FROM tld WHERE tld='$tld';");
719    if (!$db->next_record()) {
720      $err->raise("admin",11);
721      return false;
722    }
723    $mode=intval($mode);
724    if ($mode==0) $mode="0";
725    $db->query("UPDATE tld SET mode='$mode' WHERE tld='$tld';");
726    return true;
727  }
728
729} /* Classe ADMIN */
730
731?>
Note: See TracBrowser for help on using the repository browser.