Changeset 1246

Show
Ignore:
Timestamp:
06/29/08 00:36:15 (2 months ago)
Author:
rats
Message:

GUI Update 4/5: inlcude

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gui/include/admin-functions.php

    r1241 r1246  
    719719                                                'URL_CHANGE_INTERFACE' => "change_user_interface.php?to_id=" . $rs->fields['domain_admin_id'], 
    720720                                                'USR_USERNAME' => $rs->fields['domain_name'], 
     721                                                'TR_EDIT_DOMAIN' => tr('Edit domain'), 
     722                                                'TR_EDIT_USR' => tr('Edit user'), 
    721723                                                ) 
    722724                                        ); 
     
    943945 
    944946                if ($sub_max != -1) { 
    945                         if ($sub_max == 0) $rsub_uf = '_on_'; 
     947                        if ($sub_max == 0) 
     948                                $rsub_uf = '_on_'; 
    946949 
    947950                        $rsub_current += $sub_current; 
     
    950953 
    951954                if ($als_max != -1) { 
    952                         if ($als_max == 0) $rals_uf = '_on_'; 
     955                        if ($als_max == 0) 
     956                                $rals_uf = '_on_'; 
    953957 
    954958                        $rals_current += $als_current; 
     
    956960                } 
    957961 
    958                 if ($mail_max == 0) $rmail_uf = '_on_'; 
     962                if ($mail_max == 0) 
     963                        $rmail_uf = '_on_'; 
    959964 
    960965                $rmail_current += $mail_current; 
    961966                $rmail_max += $mail_max; 
    962967 
    963                 if ($ftp_max == 0) $rftp_uf = '_on_'; 
     968                if ($ftp_max == 0) 
     969                        $rftp_uf = '_on_'; 
    964970 
    965971                $rftp_current += $ftp_current; 
     
    967973 
    968974                if ($sql_db_max != -1) { 
    969                         if ($sql_db_max == 0) $rsql_db_uf = '_on_'; 
     975                        if ($sql_db_max == 0) 
     976                                $rsql_db_uf = '_on_'; 
    970977 
    971978                        $rsql_db_current += $sql_db_current; 
     
    974981 
    975982                if ($sql_user_max != -1) { 
    976                         if ($sql_user_max == 0) $rsql_user_uf = '_on_'; 
     983                        if ($sql_user_max == 0) 
     984                                $rsql_user_uf = '_on_'; 
    977985 
    978986                        $rsql_user_current += $sql_user_current; 
     
    980988                } 
    981989 
    982                 if ($traff_max == 0) $rtraff_uf = '_on_'; 
     990                if ($traff_max == 0) 
     991                        $rtraff_uf = '_on_'; 
    983992 
    984993                $rtraff_current += $traff_current; 
    985994                $rtraff_max += $traff_max; 
    986995 
    987                 if ($disk_max == 0) $rdisk_uf = '_on_'; 
     996                if ($disk_max == 0) 
     997                        $rdisk_uf = '_on_'; 
    988998 
    989999                $rdisk_current += $disk_current; 
     
    10321042        $als_current = records_count('alias_id', 'domain_aliasses', 'domain_id', $user_id); 
    10331043        $als_max = $rs->fields['domain_alias_limit']; 
    1034         // Sorry 4 the strange Hack, but it works - RatS 
     1044        // Sorry for the strange Hack, but it works - RatS 
    10351045        $mail_current = records_count('mail_id', 'mail_users', 'mail_type NOT RLIKE \'_catchall\' AND domain_id', $user_id); 
    10361046        $mail_max = $rs->fields['domain_mailacc_limit']; 
    10371047 
    1038         $ftp_current = sub_records_rlike_count('domain_name', 'domain', 'domain_id', $user_id, 
    1039                 'userid', 'ftp_users', 'userid', '@', '' 
    1040                 ); 
     1048        $ftp_current = sub_records_rlike_count( 'domain_name', 'domain', 'domain_id', $user_id, 
     1049                                                                                        'userid', 'ftp_users', 'userid', '@', ''); 
    10411050 
    10421051        $ftp_current += sub_records_rlike_count('subdomain_name', 'subdomain', 'domain_id', $user_id, 
    1043                 'userid', 'ftp_users', 'userid', '@', '' 
    1044                 ); 
     1052                                                                                        'userid', 'ftp_users', 'userid', '@', ''); 
    10451053 
    10461054        $ftp_current += sub_records_rlike_count('alias_name', 'domain_aliasses', 'domain_id', $user_id, 
    1047                 'userid', 'ftp_users', 'userid', '@', '' 
    1048                 ); 
     1055                                                                                        'userid', 'ftp_users', 'userid', '@', ''); 
    10491056 
    10501057        $ftp_max = $rs->fields['domain_ftpacc_limit']; 
     
    10531060        $sql_db_max = $rs->fields['domain_sqld_limit']; 
    10541061 
    1055         $sql_user_current = sub_records_count('sqld_id', 'sql_database', 'domain_id', $user_id, 
    1056                 'sqlu_id', 'sql_user', 'sqld_id', '', '' 
    1057                 ); 
     1062        $sql_user_current = sub_records_count(  'sqld_id', 'sql_database', 'domain_id', $user_id, 
     1063                                                                                        'sqlu_id', 'sql_user', 'sqld_id', '', ''); 
    10581064 
    10591065        $sql_user_max = $rs->fields['domain_sqlu_limit']; 
     
    10631069        $disk_max = $rs->fields['domain_disk_limit']; 
    10641070 
    1065         return array($sub_current, $sub_max, 
    1066                 $als_current, $als_max, 
    1067                 $mail_current, $mail_max, 
    1068                 $ftp_current, $ftp_max, 
    1069                 $sql_db_current, $sql_db_max, 
    1070                 $sql_user_current, $sql_user_max, 
    1071                 $traff_max, 
    1072                 $disk_max); 
     1071        return array( 
     1072                        $sub_current, $sub_max, $als_current, $als_max, 
     1073                        $mail_current, $mail_max, $ftp_current, $ftp_max, 
     1074                        $sql_db_current, $sql_db_max, $sql_user_current, 
     1075                        $sql_user_max, $traff_max, $disk_max); 
    10731076} 
    10741077 
     
    22242227                        WHERE 
    22252228                                user_id = ? 
    2226  
    22272229SQL_QUERY; 
    22282230 
     
    22472249 </head> 
    22482250 <body> 
    2249   <center
     2251  <div align="center"
    22502252   <table width="100%" height="95%"> 
    22512253    <tr align="center"> 
     
    22572259    </tr> 
    22582260   </table> 
    2259   </center
     2261  </div
    22602262 </body> 
    22612263</html> 
     
    23542356        $mail_result = mail($to, encode($subject), $message, $headers); 
    23552357        $mail_status = ($mail_result) ? 'OK' : 'NOT OK'; 
    2356         write_log("$admin_login: Auto Ticket To: |$to|, From: |$from|, Status: |$mail_status|!"); 
     2358        write_log(sprintf("%s send ticket To: %s, From: %s, Status: %s!", $_SESSION['user_logged'], $toname . ": " . $to_email, $fromname . ": " . $from_email, $mail_status)); 
    23572359} 
    23582360 
  • trunk/gui/include/calc-functions.php

    r1241 r1246  
    11<?php 
    22/** 
    3  * ispCP (OMEGA) a Virtual Hosting Control Panel 
     3 * ispCP ω (OMEGA) a Virtual Hosting Control System 
    44 * 
    5  *  @copyright  2001-2006 by moleSoftware GmbH 
    6  *  @copyright  2006-2007 by ispCP | http://isp-control.net 
    7  *  @link               http://isp-control.net 
    8  *  @author             ispCP Team (2007) 
     5 * @copyright   2001-2006 by moleSoftware GmbH 
     6 * @copyright   2006-2008 by ispCP | http://isp-control.net 
     7 * @version     SVN: $ID$ 
     8 * @link                http://isp-control.net 
     9 * @author              ispCP Team 
    910 * 
    10  *  @license 
    11  *  This program is free software; you can redistribute it and/or modify it under 
    12  *  the terms of the MPL General Public License as published by the Free Software 
    13  *  Foundation; either version 1.1 of the License, or (at your option) any later 
    14  *  version. 
    15  *  You should have received a copy of the MPL Mozilla Public License along with 
    16  *  this program; if not, write to the Open Source Initiative (OSI) 
    17  *  http://opensource.org | osi@opensource.org 
    18  **/ 
    19  
    20  
     11 * @license 
     12 *   This program is free software; you can redistribute it and/or modify it under 
     13 *   the terms of the MPL General Public License as published by the Free Software 
     14 *   Foundation; either version 1.1 of the License, or (at your option) any later 
     15 *   version. 
     16 *   You should have received a copy of the MPL Mozilla Public License along with 
     17 *   this program; if not, write to the Open Source Initiative (OSI) 
     18 *   http://opensource.org | osi@opensource.org 
     19 */ 
    2120 
    2221function calc_bars($crnt, $max, $bars_max) { 
     
    3534                 sprintf("%d", $bars) 
    3635                ); 
    37  
    3836} 
    3937 
     
    9593 
    9694function generate_rand_salt($min = 46, $max = 126) { 
    97  
    98     $salt = chr(mt_rand($min, $max)); 
    99  
     95    $salt  = chr(mt_rand($min, $max)); 
    10096    $salt .= chr(mt_rand($min, $max)); 
    101  
    10297    return $salt; 
    103  
    10498} 
    10599 
    106100function get_salt_from($data) { 
    107  
    108  
    109101    $salt = substr($data, 0, 2); 
    110  
    111102    return $salt; 
    112  
    113  
    114103} 
    115104 
    116105function crypt_user_pass($data) { 
    117  
    118106        $res = md5($data); 
    119107    return $res; 
    120  
    121108} 
    122109 
    123110function crypt_user_ftp_pass($data) { 
    124  
    125111    $res = crypt($data, generate_rand_salt()); 
    126112    return $res; 
    127  
    128113} 
    129114 
    130  
    131115function check_user_pass($crdata, $data ) { 
    132  
    133116    $salt = get_salt_from($crdata); 
    134117    $udata = crypt($data, $salt); 
    135  
    136118    return ($udata == $crdata); 
    137119} 
    138120 
    139121function _passgen() { 
    140  
    141122    $pw = ''; 
    142123 
    143124    for($i = 0; $i <= Config::get('PASSWD_CHARS'); $i++) { 
    144  
    145125        $z = 0; 
    146126 
     
    148128            $z = mt_rand(42, 123); 
    149129        } while($z >= 91 && $z <= 96); 
    150  
    151130        $pw .= chr($z); 
    152  
    153131    } 
    154  
    155132    return $pw; 
    156  
    157133} 
    158134 
    159135function passgen() { 
    160  
    161136    $pw = null; 
    162137 
     
    164139        $pw = _passgen(); 
    165140    } 
    166  
    167141    return $pw; 
    168142 
    169143} 
    170144 
    171 function translate_limit_value($value, $autosize = false) 
    172 
     145function translate_limit_value($value, $autosize = false) { 
    173146    if ($value == -1) { 
    174147        return tr('disabled'); 
  • trunk/gui/include/class.pTemplate.php

    r1241 r1246  
    44 * 
    55 * @copyright   2001-2006 by moleSoftware GmbH 
    6  * @copyright   2006-2007 by ispCP | http://isp-control.net 
     6 * @copyright   2006-2008 by ispCP | http://isp-control.net 
    77 * @version     SVN: $ID$ 
    88 * @link                http://isp-control.net 
     
    171171                        $this->dtpl_data[$t_name] = $t_value; 
    172172 
    173                         $this->dtpl_data[strtoupper($t_name)] = @$value; 
     173                        $this->dtpl_data[strtoupper($t_name)] = @$t_value; 
    174174 
    175175                        $this->dtpl_options[$t_name] = ''; 
  • trunk/gui/include/client-functions.php

    r1241 r1246  
    55 * @copyright   2001-2006 by moleSoftware GmbH 
    66 * @copyright   2006-2008 by ispCP | http://isp-control.net 
    7  * @version             $ID$ 
     7 * @version             SVN: $ID$ 
    88 * @link                http://isp-control.net 
    99 * @author              ispCP Team 
     
    7979function get_domain_running_sub_cnt(&$sql, $domain_id) { 
    8080        $query = <<<SQL_QUERY 
    81         select 
    82             count(subdomain_id) as cnt 
    83         from 
     81        SELECT 
     82            COUNT(subdomain_id) AS cnt 
     83        FROM 
    8484            subdomain 
    85         where 
     85        WHERE 
    8686            domain_id = ? 
    8787SQL_QUERY; 
     
    9696function get_domain_running_als_cnt(&$sql, $domain_id) { 
    9797        $query = <<<SQL_QUERY 
    98         select 
    99             count(alias_id) as cnt 
    100         from 
     98        SELECT 
     99            COUNT(alias_id) AS cnt 
     100        FROM 
    101101            domain_aliasses 
    102         where 
     102        WHERE 
    103103            domain_id = ? 
    104104 
     
    172172function get_domain_running_dmn_ftp_acc_cnt(&$sql, $domain_id) { 
    173173        $query = <<<SQL_QUERY 
    174         select 
     174        SELECT 
    175175            domain_name 
    176         from 
     176        FROM 
    177177            domain 
    178         where 
     178        WHERE 
    179179            domain_id = ? 
    180180SQL_QUERY; 
     
    185185 
    186186        $query = <<<SQL_QUERY 
    187         select 
    188             count(userid) as cnt 
    189         from 
     187        SELECT 
     188            COUNT(userid) AS cnt 
     189        FROM 
    190190            ftp_users 
    191         where 
    192             userid rlike
     191        WHERE 
     192            userid RLIKE
    193193SQL_QUERY; 
    194194 
     
    202202function get_domain_running_sub_ftp_acc_cnt(&$sql, $domain_id) { 
    203203        $query = <<<SQL_QUERY 
    204         select 
     204        SELECT 
    205205            subdomain_name 
    206         from 
     206        FROM 
    207207            subdomain 
    208         where 
    209             domain_id = ? 
    210         order by 
     208        WHERE 
     209            domain_id = ? 
     210        ORDER BY 
    211211            subdomain_id 
    212212SQL_QUERY; 
    213213 
    214214        $query2 = <<<SQL_QUERY 
    215         select 
     215        SELECT 
    216216            domain_name 
    217         from 
     217        FROM 
    218218            domain 
    219         where 
     219        WHERE 
    220220            domain_id = ? 
    221221SQL_QUERY; 
     
    230230 
    231231                $query = <<<SQL_QUERY 
    232             select 
    233                 count(userid) as cnt 
    234             from 
     232            SELECT 
     233                COUNT(userid) AS cnt 
     234            FROM 
    235235                ftp_users 
    236             where 
    237                 userid rlike
     236            WHERE 
     237                userid RLIKE
    238238SQL_QUERY; 
    239239 
     
    250250function get_domain_running_als_ftp_acc_cnt(&$sql, $domain_id) { 
    251251        $query = <<<SQL_QUERY 
    252         select 
     252        SELECT 
    253253            alias_name 
    254         from 
     254        FROM 
    255255            domain_aliasses 
    256         where 
    257             domain_id = ? 
    258         order by 
     256        WHERE 
     257            domain_id = ? 
     258        ORDER BY 
    259259            alias_id 
    260260SQL_QUERY; 
     
    268268 
    269269                $query = <<<SQL_QUERY 
    270             select 
    271                 count(userid) as cnt 
    272             from 
     270            SELECT 
     271                COUNT(userid) AS cnt 
     272            FROM 
    273273                ftp_users 
    274             where 
    275                 userid rlike
     274            WHERE 
     275                userid RLIKE
    276276SQL_QUERY; 
    277277 
     
    301301function get_domain_running_sqld_acc_cnt(&$sql, $domain_id) { 
    302302        $query = <<<SQL_QUERY 
    303         select 
    304             count(sqld_id) as cnt 
    305         from 
     303        SELECT 
     304            COUNT(sqld_id) AS cnt 
     305        FROM 
    306306            sql_database 
    307         where 
     307        WHERE 
    308308            domain_id = ? 
    309309SQL_QUERY; 
     
    318318function get_domain_running_sqlu_acc_cnt(&$sql, $domain_id) { 
    319319        $query = <<<SQL_QUERY 
    320         select distinct 
     320        SELECT DISTINCT 
    321321            t1.sqlu_name 
    322         from 
    323             sql_user as t1, sql_database as t2 
    324         where 
     322        FROM 
     323            sql_user AS t1, sql_database AS t2 
     324        WHERE 
    325325            t2.domain_id = ? 
    326           and 
     326          AND 
    327327            t2.sqld_id = t1.sqld_id 
    328328SQL_QUERY; 
     
    411411 
    412412        $query = <<<SQL_QUERY 
    413         select 
     413        SELECT 
    414414            * 
    415         from 
     415        FROM 
    416416            custom_menus 
    417         where 
     417        WHERE 
    418418            menu_level = 'user' 
    419           or 
     419          OR 
    420420            menu_level = 'all' 
    421421SQL_QUERY; 
     
    472472                $tpl->assign('ISACTIVE_AWSTATS', ''); 
    473473        } else { 
    474                 $tpl->assign('AWSTSTS', 'http://' . $_SERVER['HTTP_HOST'] . '/stats'); 
     474                $tpl->assign( 
     475                        array( 
     476                                'AWSTATS_PATH' => 'http://' . $_SESSION['user_logged'] . '/stats/', 
     477                                'AWSTATS_TARGET' => '_blank' 
     478                                ) 
     479                        ); 
    475480        } 
    476481 
     
    531536 
    532537        $query = <<<SQL_QUERY 
    533         select 
     538        SELECT 
    534539            * 
    535         from 
     540        FROM 
    536541            custom_menus 
    537         where 
     542        WHERE 
    538543            menu_level = 'user' 
    539           or 
     544          OR 
    540545            menu_level = 'all' 
    541546SQL_QUERY; 
     
    560565 
    561566                        $tpl->assign( 
    562                                 array('BUTTON_LINK' => $menu_link, 
     567                                array( 
     568                                        'BUTTON_LINK' => $menu_link, 
    563569                                        'BUTTON_NAME' => $menu_name, 
    564570                                        'BUTTON_TARGET' => $menu_target, 
     
    572578                } // end while 
    573579        } // end else 
    574         if (!Config::get('ISPCP_SUPPORT_SYSTEM')) { 
     580        if (!$cfg['ISPCP_SUPPORT_SYSTEM']) { 
    575581                $tpl->assign('SUPPORT_SYSTEM', ''); 
    576582        } 
    577583 
    578         if (Config::get('AWSTATS_ACTIVE') == 'no') { 
    579                 $tpl->assign('AWSTSTS', ''); 
     584        if (Config::get('AWSTATS_ACTIVE') == 'yes') { 
     585                $tpl->assign('ACTIVE_AWSTSTS', ''); 
    580586        } else { 
    581                 $tpl->assign('AWSTSTS', 'http://' . $_SERVER['HTTP_HOST'] . '/stats'); 
     587                $tpl->assign( 
     588                        array( 
     589                                'AWSTATS_PATH' => 'http://' . $_SESSION['user_logged'] . '/stats/', 
     590                                'AWSTATS_TARGET' => '_blank' 
     591                                ) 
     592                        ); 
    582593        } 
    583594 
     
    587598function get_user_domain_id(&$sql, $user_id) { 
    588599        $query = <<<SQL_QUERY 
    589         select 
     600        SELECT 
    590601            domain_id 
    591         from 
     602        FROM 
    592603            domain 
    593         where 
     604        WHERE 
    594605            domain_admin_id = ? 
    595606SQL_QUERY; 
     
    630641        $query = <<<SQL_QUERY 
    631642                SELECT 
    632                         COUNT(sqlu_id) as cnt 
     643                        COUNT(sqlu_id) AS cnt 
    633644                FROM 
    634645                        sql_user 
     
    645656        // let's get sql user common data; 
    646657        $query = <<<SQL_QUERY 
    647          select 
     658         SELECT 
    648659            t1.sqld_id, t1.sqlu_name, t2.sqld_name, t1.sqlu_name 
    649          from 
    650             sql_user as t1, 
    651             sql_database as t2 
    652          where 
     660         FROM 
     661            sql_user AS t1, 
     662            sql_database AS t2 
     663         WHERE 
    653664            t1.sqld_id = t2.sqld_id 
    654            and 
     665           AND 
    655666            t2.domain_id = ? 
    656            and 
     667           AND 
    657668            t1.sqlu_id = ? 
    658669SQL_QUERY; 
     
    674685                // revoke grants on global level, if any; 
    675686                $query = <<<SQL_QUERY 
    676                 revoke all on *.* from ?@'%' 
     687                REVOKE ALL ON *.* FROM ?@'%' 
    677688SQL_QUERY; 
    678689                $rs = exec_query($sql, $query, array($db_user_name)); 
    679690                $query = <<<SQL_QUERY 
    680                 revoke all on *.* from ?@localhost 
     691                       REVOKE ALL ON *.* FROM ?@localhost 
    681692SQL_QUERY; 
    682693                $rs = exec_query($sql, $query, array($db_user_name)); 
    683694                // delete user record from mysql.user table; 
    684695                $query = <<<SQL_QUERY 
    685          delete from 
     696         DELETE FROM 
    686697                    mysql.user 
    687          where 
    688                    Host = '%' 
    689          and 
    690                  User = ? 
     698         WHERE 
     699                       Host = '%' 
     700           AND 
     701                               User = ? 
    691702SQL_QUERY; 
    692703                $rs = exec_query($sql, $query, array($db_user_name)); 
    693704 
    694705                $query = <<<SQL_QUERY 
    695         delete from 
    696                 mysql.user 
    697         where 
    698                 Host = 'localhost' 
    699         and 
    700                 User = ? 
     706                       DELETE FROM 
     707                               mysql.user 
     708                       WHERE 
     709                               Host = 'localhost' 
     710                         AND 
     711                               User = ? 
    701712SQL_QUERY; 
    702713                $rs = exec_query($sql, $query, array($db_user_name)); 
    703714                // flush privileges. 
    704715                $query = <<<SQL_QUERY 
    705                 flush privileges 
     716                FLUSH PRIVILEGES; 
    706717SQL_QUERY; 
    707718                $rs = exec_query($sql, $query, array()); 
     
    709720                $new_db_name = str_replace("_", "\\_", $db_name); 
    710721                $query = <<<SQL_QUERY 
    711                 revoke all on $new_db_name.* from ?@'%' 
     722                REVOKE ALL ON $new_db_name.* FROM ?@'%' 
    712723SQL_QUERY; 
    713724                $rs = exec_query($sql, $query, array($db_user_name)); 
    714725                $query = <<<SQL_QUERY 
    715                 revoke all on $new_db_name.* from ?@localhost 
     726                       REVOKE ALL ON $new_db_name.* FROM ?@localhost 
    716727SQL_QUERY; 
    717728                $rs = exec_query($sql, $query, array($db_user_name)); 
     
    723734                $tpl->assign('SQL_SUPPORT', ''); 
    724735        } 
    725  
    726736        if (isset($_SESSION['email_support']) && $_SESSION['email_support'] == "no") { 
    727737                $tpl->assign('ADD_EMAIL', ''); 
    728738        } 
    729  
    730739        if (isset($_SESSION['subdomain_support']) && $_SESSION['subdomain_support'] == "no") { 
    731740                $tpl->assign('SUBDOMAIN_SUPPORT', ''); 
     
    734743                $tpl->assign('DOMAINALIAS_SUPPORT', ''); 
    735744        } 
    736  
    737745        if (isset($_SESSION['subdomain_support']) && $_SESSION['subdomain_support'] == "no") { 
    738746                $tpl->assign('SUBDOMAIN_SUPPORT_CONTENT', ''); 
     
    741749                $tpl->assign('DOMAINALIAS_SUPPORT_CONTENT', ''); 
    742750        } 
    743  
    744751        if (isset($_SESSION['alias_support']) && $_SESSION['alias_support'] == "no" && isset($_SESSION['subdomain_support']) && $_SESSION['subdomain_support'] == "no") { 
    745752                $tpl->assign('DMN_MNGMNT', ''); 
     
    776783function delete_sql_database(&$sql, $dmn_id, $db_id) { 
    777784        $query = <<<SQL_QUERY 
    778         select 
    779             sqld_name as db_name 
    780         from 
     785        SELECT 
     786            sqld_name AS db_name 
     787        FROM 
    781788            sql_database 
    782         where 
    783             domain_id = ? 
    784           and 
     789        WHERE 
     790            domain_id = ? 
     791          AND 
    785792            sqld_id = ? 
    786793SQL_QUERY; 
     
    795802        // have we any users assigned to this database; 
    796803        $query = <<<SQL_QUERY 
    797         select 
    798             t2.sqlu_id as db_user_id, 
    799             t2.sqlu_name as db_user_name 
    800         from 
    801             sql_database as t1, 
    802             sql_user as t2 
    803         where 
     804        SELECT 
     805            t2.sqlu_id AS db_user_id, 
     806            t2.sqlu_name AS db_user_name 
     807        FROM 
     808            sql_database AS t1, 
     809            sql_user AS t2 
     810        WHERE 
    804811            t1.sqld_id = t2.sqld_id 
    805           and 
     812          AND 
    806813            t1.domain_id = ? 
    807           and 
     814          AND 
    808815            t1.sqld_id = ? 
    809816SQL_QUERY; 
     
    823830        } 
    824831        // drop desired database; 
    825         $query = <<<SQL_QUERY 
    826         drop database 
    827 SQL_QUERY; 
    828  
    829         $query .= $db_name; 
     832        $query = "DROP DATABASE IF EXISTS ".$db_name.";"; 
    830833 
    831834        $rs = exec_query($sql, $query, array()); 
     
    834837        // delete desired database from the ispcp sql_database table; 
    835838        $query = <<<SQL_QUERY 
    836         delete from 
     839        DELETE FROM 
    837840            sql_database 
    838         where 
    839             domain_id = ? 
    840           and 
     841        WHERE 
     842            domain_id = ? 
     843          AND 
    841844            sqld_id = ? 
    842845SQL_QUERY; 
  • trunk/gui/include/database-update-functions.php

    r1241 r1246  
    2828 
    2929/* 
    30  * Select the current revision from the database and return it 
     30 * Get the current revision from the database and return it 
    3131 */ 
    3232function getCurrentRevision() { 
    3333        $sql = Database::getInstance(); 
    3434 
    35         $query = "SELECT * FROM `config` WHERE `name` = 'DATABASE_REVISION'"; 
    36         $rs = $sql->Execute($query); 
    37         $current_revision = (int)$rs->fields['value']; 
    38  
    39         return $current_revision; 
     35        $query  = "SELECT * FROM `config` WHERE `name` = 'DATABASE_REVISION'"; 
     36        $rs             = $sql->Execute($query); 
     37 
     38        return (int)$rs->fields['value']; 
    4039} 
    4140 
     
    5857 
    5958/* 
    60  * Check for existenz of a available update 
     59 * Check for existence of an available update 
    6160 */ 
    6261function checkNewRevisionExists() { 
     
    7473function returnFunctionName($revision) { 
    7574        $functionName = "_databaseUpdate_" . $revision; 
    76          
     75 
    7776        return $functionName; 
    7877} 
     
    8382function executeDatabaseUpdates() { 
    8483        $sql = Database::getInstance(); 
    85          
     84        $failedUpdate = false; 
     85 
    8686        while(checkNewRevisionExists()) { 
     87                // Get the next database update revision 
    8788                $newRevision    = getNextRevision(); 
     89 
     90                // Get the needed function name 
    8891                $functionName   = returnFunctionName($newRevision); 
    8992 
    90                 if(function_exists($functionName)) { 
    91                         $queryArray     = $functionName(); 
    92                          
    93                         // Query to set the new Database Revision 
    94                         $queryArray[]   = "UPDATE `config` SET `value` = '$newRevision' WHERE `name` = 'DATABASE_REVISION'"; 
    95                          
    96                         $sql->StartTrans(); 
    97                          
    98                         foreach($queryArray as $query) { 
    99                                 $sql->Execute($query);                           
    100                         } 
    101                          
    102                         // Prompt a error when a update fails 
    103                         if ($sql->HasFailedTrans()) { 
    104                                 set_page_message(tr("Db update %s failed", $newRevision)); 
    105                         } 
    106                          
    107                         $sql->CompleteTrans(); 
    108                         unset($queryArray); 
     93                // Pull the query from the update function using a variable function 
     94                $queryArray     = $functionName(); 
     95 
     96                // Add the query, to set the new Database Revision, to our queryArray 
     97                $queryArray[]   = "UPDATE `config` SET `value` = '$newRevision' WHERE `name` = 'DATABASE_REVISION'"; 
     98 
     99                // Start the Transaction 
     100                $sql->StartTrans(); 
     101 
     102                // Execute every query in our queryArray 
     103                foreach($queryArray as $query) { 
     104                        $sql->Execute($query); 
    109105                } 
     106 
     107                // Set failedUpdate to true if an databaseUpdate failed 
     108                if ($sql->HasFailedTrans()) 
     109                        $failedUpdate = true; 
     110 
     111                // Complete the Transactin and rollback if nessessary 
     112                $sql->CompleteTrans(); 
     113 
     114                // Display an error if nessessary 
     115                if($failedUpdate) 
     116                        system_message(tr("Database update %s failed", $newRevision)); 
    110117        } 
    111118} 
    112119 
    113120/* 
    114  * Insert the update functions below this entry please. The revision should be ascending
    115  * Don't insert a update twice! 
     121 * Insert the update functions below this entry. The revision has to be ascending and unique
     122 * Each databaseUpdate function has to return a array. Even if the array contains only one entry. 
    116123 */ 
    117124 
     
    120127 */ 
    121128function _databaseUpdate_1() { 
    122         $sqlUpd = "INSERT INTO config (name, value) VALUES (DATABASE_REVISION , 1)"; 
    123          
     129        $sqlUpd = array(); 
     130 
     131        $sqlUpd[] = "INSERT INTO `config` (name, value) VALUES ('DATABASE_REVISION' , '1')"; 
     132 
    124133        return $sqlUpd; 
    125134} 
     
    138147                                . "SET `mail_addr` = CONCAT(`mail_acc`,'@',`domain_name`)" 
    139