Пример #1
0
 function render_html()
 {
     // Title + Summary
     print "<h3>DATABASE BACKUP</h3><br>";
     print "<p>This page allows an administrator to perform an export of the entire MySQL database and download it as a file. This feature\n\t\t\tensures that no matter who runs your instance of the Amberdms Billing System, your data can always be retrieved.</p>";
     print "<p>The file generated is a standard SQL file compressed with gzip, it can be easily restored using the MySQL command line or\n\t\t\tvia a utility such as phpmyadmin.</p>";
     // report on usage
     $sql_obj = new sql_query();
     $usage = $sql_obj->stats_diskusage();
     format_msgbox("info", "<p>Estimated download size: " . format_size_human($usage) . " (before compression)</p>");
     // run check for file-system based journal files
     $sql_obj = new sql_query();
     $sql_obj->string = "SELECT id FROM file_uploads WHERE file_location != 'db' LIMIT 1";
     $sql_obj->execute();
     if ($sql_obj->num_rows()) {
         format_msgbox("important", "<p>Some of the files stored in the journal have been saved to the filesystem rather than the MySQL database. This backup will provide a copy of the database, but you will also need to download the contents of the data/ directory.</p>");
     }
     // export link
     print "<br>";
     print "<a class=\"button\" href=\"admin/db_backup-process.php\">Export Database</a>";
 }
 if ($data["BLACKLIST_ENABLE"] == "on") {
     $data["BLACKLIST_ENABLE"] = "enabled";
 } else {
     $data["BLACKLIST_ENABLE"] = "disabled";
 }
 if ($data["PHONE_HOME"] == "on") {
     $data["PHONE_HOME"] = "enabled";
 } else {
     $data["PHONE_HOME"] = "disabled";
 }
 // check max upload size
 $system_upload_max_filesize = format_size_bytes(ini_get('upload_max_filesize'));
 if ($data["UPLOAD_MAXBYTES"] > $system_upload_max_filesize) {
     // adjust the value to the max possible and add notification about it.
     $data["UPLOAD_MAXBYTES"] = $system_upload_max_filesize;
     log_write("notification", "process", "The maximum upload is " . format_size_human($system_upload_max_filesize) . " due to server limits, the maximum upload value for this application has been adjusted to suit.");
 }
 /*
 	Error Handling
 */
 if (error_check()) {
     $_SESSION["error"]["form"]["config_application"] = "failed";
     header("Location: ../index.php?page=admin/config_application.php");
     exit(0);
 } else {
     $_SESSION["error"] = array();
     /*
     	Start Transaction
     */
     $sql_obj = new sql_query();
     $sql_obj->trans_begin();
Пример #3
0
function log_debug_render()
{
    log_debug("inc_misc", "Executing log_debug_render()");
    if (!empty($_SESSION["mode"])) {
        if ($_SESSION["mode"] == "cli") {
            /*
            	CLI Interface
            
            	Limited to a statistical display only.
            */
            // get first time entry
            $time_first = (double) $_SESSION["user"]["log_debug"][0]["time_sec"] + (double) $_SESSION["user"]["log_debug"][0]["time_usec"];
            // count SQL queries
            $num_sql_queries = 0;
            $num_cache_hits = 0;
            // run through the log to get stats
            foreach ($_SESSION["user"]["log_debug"] as $log_record) {
                // get last time entry
                $time_last = (double) $log_record["time_sec"] + (double) $log_record["time_usec"];
                // last memmor
                $memory_last = $log_record["memory"];
                // choose formatting
                switch ($log_record["type"]) {
                    case "sql":
                        $num_sql_queries++;
                        break;
                    case "cache":
                        $num_cache_hits++;
                        break;
                    default:
                        // nothing todo
                        break;
                }
            }
            // report completion time
            $time_diff = $time_last - $time_first;
            // display
            log_write("debug", "stats", "----");
            log_write("debug", "stats", "Application execution time:\t" . $time_diff . " seconds");
            log_write("debug", "stats", "Total Memory Consumption:\t" . number_format($memory_last) . " bytes.");
            log_write("debug", "stats", "SQL Queries Executed:\t" . number_format($num_sql_queries) . " queries.");
            log_write("debug", "stats", "Total Cache Hits:\t\t" . number_format($num_cache_hits) . " cache lookups.");
            log_write("debug", "stats", "----");
        }
        // end if CLI
    } else {
        /*
        	Web Interface
        */
        print "<p><b>Debug Output:</b></p>";
        print "<p><i>Please be aware that debugging will cause some impact on performance and should be turned off in production.</i></p>";
        // table header
        print "<table class=\"table_content\" width=\"100%\" cellspacing=\"0\">";
        print "<tr class=\"header\">";
        print "<td nowrap><b>Time</b></td>";
        print "<td nowrap><b>Memory</b></td>";
        print "<td nowrap><b>Type</b></td>";
        print "<td nowrap><b>Category</b></td>";
        print "<td><b>Message/Content</b></td>";
        print "</tr>";
        // get first time entry
        $time_first = (double) $_SESSION["user"]["log_debug"][0]["time_sec"] + (double) $_SESSION["user"]["log_debug"][0]["time_usec"];
        // count SQL queries
        $num_sql_queries = 0;
        $num_cache_hits = 0;
        // content
        foreach ($_SESSION["user"]["log_debug"] as $log_record) {
            // get last time entry
            $time_last = (double) $log_record["time_sec"] + (double) $log_record["time_usec"];
            // choose formatting
            switch ($log_record["type"]) {
                case "error":
                    print "<tr bgcolor=\"#ff5a00\">";
                    break;
                case "warning":
                    print "<tr bgcolor=\"#ffeb68\">";
                    break;
                case "sql":
                    print "<tr bgcolor=\"#7bbfff\">";
                    $num_sql_queries++;
                    break;
                case "cache":
                    print "<tr bgcolor=\"#ddf9ff\">";
                    $num_cache_hits++;
                    break;
                default:
                    print "<tr>";
                    break;
            }
            // display
            print "<td nowrap>" . $time_last . "</td>";
            print "<td nowrap>" . format_size_human($log_record["memory"]) . "</td>";
            print "<td nowrap>" . $log_record["type"] . "</td>";
            print "<td nowrap>" . $log_record["category"] . "</td>";
            print "<td>" . $log_record["content"] . "</td>";
            print "</tr>";
        }
        print "</table>";
        // report completion time
        $time_diff = $time_last - $time_first;
        print "<p>Completed in {$time_diff} seconds.</p>";
        // report number of SQL queries
        print "<p>Executed {$num_sql_queries} of SQL queries.</p>";
        print "<p>Executed {$num_cache_hits} cache lookups.</p>";
    }
    // end if web UI
}
Пример #4
0
 function render_field($fieldname)
 {
     log_debug("form", "Executing render_field({$fieldname})");
     $helpmessagestatus = "false";
     switch ($this->structure[$fieldname]["type"]) {
         case "input":
             // set default size
             if (!isset($this->structure[$fieldname]["options"]["width"])) {
                 $this->structure[$fieldname]["options"]["width"] = 250;
             }
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             // display
             print "<input id=\"{$fieldname}\" name=\"{$fieldname}\" ";
             $css_field_class = array();
             if (isset($this->structure[$fieldname]["defaultvalue"])) {
                 print "value=\"" . htmlentities($this->structure[$fieldname]["defaultvalue"], ENT_QUOTES, "UTF-8") . "\" ";
             } elseif (isset($this->structure[$fieldname]["options"]["help"])) {
                 print "value=\"" . $this->structure[$fieldname]["options"]["help"] . "\" ";
                 $helpmessagestatus = "true";
                 $css_field_class[] = "helpmessage";
             }
             if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                 $css_field_class[] = $this->structure[$fieldname]["options"]["css_field_class"];
             }
             if (!empty($css_field_class)) {
                 print "class=\"";
                 foreach ($css_field_class as $css) {
                     print $css . " ";
                 }
                 print "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["max_length"])) {
                 print "maxlength=\"" . $this->structure[$fieldname]["options"]["max_length"] . "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                 print "disabled=\"disabled\" ";
             }
             print "style=\"width: " . $this->structure[$fieldname]["options"]["width"] . "px;\">";
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             print "<input type=\"hidden\" name=\"" . $fieldname . "_helpmessagestatus\" value=\"" . $helpmessagestatus . "\">";
             if (isset($this->structure[$fieldname]["options"]["autofill"])) {
                 print "<input type=\"hidden\" name=\"" . $fieldname . "_autofill\" value=\"" . $this->structure[$fieldname]["options"]["autofill"] . "\">";
             }
             break;
         case "money":
             // set default size
             if (!isset($this->structure[$fieldname]["options"]["width"])) {
                 $this->structure[$fieldname]["options"]["width"] = 50;
             }
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             // check where to set the currency symbol
             $position = sql_get_singlevalue("SELECT value FROM config WHERE name='CURRENCY_DEFAULT_SYMBOL_POSITION'");
             if ($position == "before") {
                 print sql_get_singlevalue("SELECT value FROM config WHERE name='CURRENCY_DEFAULT_SYMBOL'") . " ";
             }
             // display
             print "<input name=\"{$fieldname}\" ";
             $css_field_class = array();
             if (isset($this->structure[$fieldname]["defaultvalue"])) {
                 print "value=\"" . htmlentities($this->structure[$fieldname]["defaultvalue"], ENT_QUOTES, "UTF-8") . "\" ";
             } elseif (isset($this->structure[$fieldname]["options"]["help"])) {
                 print "value=\"" . $this->structure[$fieldname]["options"]["help"] . "\" ";
                 $helpmessagestatus = "true";
                 $css_field_class[] = "helpmessage";
             }
             if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                 $css_field_class[] = $this->structure[$fieldname]["options"]["css_field_class"];
             }
             if (!empty($css_field_class)) {
                 print "class=\"";
                 foreach ($css_field_class as $css) {
                     print $css . " ";
                 }
                 print "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["max_length"])) {
                 print "maxlength=\"" . $this->structure[$fieldname]["options"]["max_length"] . "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                 print "disabled=\"disabled\" ";
             }
             print "style=\"width: " . $this->structure[$fieldname]["options"]["width"] . "px;\">";
             if ($position == "after") {
                 print " " . sql_get_singlevalue("SELECT value FROM config WHERE name='CURRENCY_DEFAULT_SYMBOL'");
             }
             print " " . sql_get_singlevalue("SELECT value FROM config WHERE name='CURRENCY_DEFAULT_NAME'");
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             print "<input type=\"hidden\" name=\"" . $fieldname . "_helpmessagestatus\" value=\"" . $helpmessagestatus . "\">";
             break;
         case "password":
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             // set default size
             if (empty($this->structure[$fieldname]["options"]["width"])) {
                 $this->structure[$fieldname]["options"]["width"] = 250;
             }
             // display
             print "<input type=\"password\" name=\"{$fieldname}\"";
             if (isset($this->structure[$fieldname]["defaultvalue"])) {
                 print " value=\"" . $this->structure[$fieldname]["defaultvalue"] . "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                 print "disabled=\"disabled\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                 print "class=\"" . $this->structure[$fieldname]["options"]["css_field_class"] . "\" ";
             }
             print "style=\"width: " . $this->structure[$fieldname]["options"]["width"] . "px;\">";
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         case "hidden":
             if (!isset($this->structure[$fieldname]["defaultvalue"])) {
                 $this->structure[$fieldname]["defaultvalue"] = '';
             }
             print "<input type=\"hidden\" name=\"{$fieldname}\" value=\"" . $this->structure[$fieldname]["defaultvalue"] . "\">";
             break;
         case "text":
             if (!isset($this->structure[$fieldname]["defaultvalue"])) {
                 $this->structure[$fieldname]["defaultvalue"] = '';
             }
             $translation = language_translate_string($this->language, $this->structure[$fieldname]["defaultvalue"]);
             print "{$translation}";
             if (!isset($this->structure[$fieldname]["options"]["nohidden"])) {
                 print "<input type=\"hidden\" name=\"{$fieldname}\" value=\"" . $this->structure[$fieldname]["defaultvalue"] . "\">";
             }
             break;
         case "textarea":
             // set default size
             if (!isset($this->structure[$fieldname]["options"]["width"])) {
                 $this->structure[$fieldname]["options"]["width"] = 300;
             }
             if (!isset($this->structure[$fieldname]["options"]["height"])) {
                 $this->structure[$fieldname]["options"]["height"] = 35;
             }
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             // display
             print "<textarea name=\"{$fieldname}\" ";
             if (isset($this->structure[$fieldname]["options"]["wrap"])) {
                 print "wrap=\"" . $this->structure[$fieldname]["options"]["wrap"] . "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                 print "disabled=\"disabled\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                 print "class=\"" . $this->structure[$fieldname]["options"]["css_field_class"] . "\" ";
             }
             print "style=\"width: " . $this->structure[$fieldname]["options"]["width"] . "px; height: " . $this->structure[$fieldname]["options"]["height"] . "px;\">";
             if (isset($this->structure[$fieldname]["defaultvalue"])) {
                 print $this->structure[$fieldname]["defaultvalue"];
             }
             print "</textarea>";
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         case "date":
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             if (isset($this->structure[$fieldname]["defaultvalue"])) {
                 if ($this->structure[$fieldname]["defaultvalue"] == "0000-00-00" || $this->structure[$fieldname]["defaultvalue"] == 0) {
                     $date_a = array("", "", "");
                 } else {
                     $date_a = explode("-", $this->structure[$fieldname]["defaultvalue"]);
                 }
             } else {
                 $date_a = array("", "", "");
             }
             // get the format the date field needs to be shown in
             if (isset($_SESSION["user"]["dateformat"])) {
                 // fetch from user preferences
                 $format = $_SESSION["user"]["dateformat"];
             } else {
                 // user hasn't chosen a default time format yet - use the system default
                 $format = sql_get_singlevalue("SELECT value FROM config WHERE name='DATEFORMAT' LIMIT 1");
             }
             switch ($format) {
                 case "mm-dd-yyyy":
                     print "<input name=\"" . $fieldname . "_mm\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[1] . "\"> ";
                     print "<input name=\"" . $fieldname . "_dd\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[2] . "\"> ";
                     print "<input name=\"" . $fieldname . "_yyyy\" style=\"width: 50px;\" maxlength=\"4\" value=\"" . $date_a[0] . "\">";
                     print " <i>(mm/dd/yyyy)</i>";
                     break;
                 case "dd-mm-yyyy":
                     print "<input name=\"" . $fieldname . "_dd\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[2] . "\"> ";
                     print "<input name=\"" . $fieldname . "_mm\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[1] . "\"> ";
                     print "<input name=\"" . $fieldname . "_yyyy\" style=\"width: 50px;\" maxlength=\"4\" value=\"" . $date_a[0] . "\">";
                     print " <i>(dd/mm/yyyy)</i>";
                     break;
                 case "yyyy-mm-dd":
                 default:
                     print "<input name=\"" . $fieldname . "_yyyy\" style=\"width: 50px;\" maxlength=\"4\" value=\"" . $date_a[0] . "\"> ";
                     print "<input name=\"" . $fieldname . "_mm\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[1] . "\"> ";
                     print "<input name=\"" . $fieldname . "_dd\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[2] . "\">";
                     print " <i>(yyyy/mm/dd)</i>";
                     break;
             }
             // TODO: it would be good to have a javascript calender pop-up to use here.
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         case "timestamp_date":
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             if (empty($this->structure[$fieldname]["defaultvalue"])) {
                 $date_a = array("", "", "");
             } else {
                 $date_a = explode("-", date("Y-m-d", $this->structure[$fieldname]["defaultvalue"]));
             }
             print "<input name=\"" . $fieldname . "_dd\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[2] . "\"> ";
             print "<input name=\"" . $fieldname . "_mm\" style=\"width: 25px;\" maxlength=\"2\" value=\"" . $date_a[1] . "\"> ";
             print "<input name=\"" . $fieldname . "_yyyy\" style=\"width: 50px;\" maxlength=\"4\" value=\"" . $date_a[0] . "\">";
             print " <i>(dd/mm/yyyy)</i>";
             // TODO: it would be good to have a javascript calender pop-up to use here.
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         case "hourmins":
             if (empty($this->structure[$fieldname]["defaultvalue"])) {
                 $time_hours = "";
                 $time_mins = "";
             } else {
                 $time_processed = explode(":", time_format_hourmins($this->structure[$fieldname]["defaultvalue"]));
                 $time_hours = $time_processed[0];
                 $time_mins = $time_processed[1];
             }
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             print "<input name=\"" . $fieldname . "_hh\" style=\"width: 25px;\" maxlength=\"2\" value=\"{$time_hours}\"> hours ";
             print "<input name=\"" . $fieldname . "_mm\" style=\"width: 25px;\" maxlength=\"2\" value=\"{$time_mins}\"> mins";
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         case "radio":
             /*
             	there are two ways to draw radio form entries
             	
             	1. Just pass it the array of values, and the code will translate them using the language DB
             
             	2. Pass it an array of translation values with the array keys matching the value names. This
             	   is useful when you want to populate the radio with data from a different table.
             */
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             if (isset($this->structure[$fieldname]["translations"])) {
                 $translations = $this->structure[$fieldname]["translations"];
             } else {
                 // get translation for all options
                 $translations = language_translate($this->language, $this->structure[$fieldname]["values"]);
             }
             // if there is only 1 option avaliable, see if we should auto-select it.
             if (isset($this->structure[$fieldname]["options"]["autoselect"]) && isset($this->structure[$fieldname]["values"])) {
                 if (count($this->structure[$fieldname]["values"]) == 1) {
                     $autoselect = 1;
                 }
             }
             // display all the radio buttons
             foreach ($this->structure[$fieldname]["values"] as $value) {
                 // is the current row, the one that is in use? If so, add the 'selected' tag to it
                 if (isset($this->structure[$fieldname]["defaultvalue"]) && $value == $this->structure[$fieldname]["defaultvalue"]) {
                     print "<input checked ";
                 } elseif (isset($autoselect)) {
                     print "<input checked ";
                 } else {
                     print "<input ";
                 }
                 // if actions enabled, configure all the actions that have been defined
                 if (isset($this->actions[$fieldname])) {
                     print "onclick=\"";
                     foreach (array_keys($this->actions[$fieldname]) as $target_field) {
                         if (isset($this->actions[$fieldname][$target_field][$value])) {
                             $action = $this->actions[$fieldname][$target_field][$value];
                         } else {
                             $action = $this->actions[$fieldname][$target_field]["default"];
                         }
                         switch ($action) {
                             case "show":
                                 print "obj_show('" . $target_field . "'); ";
                                 break;
                             case "hide":
                                 print "obj_hide('" . $target_field . "'); ";
                                 break;
                         }
                     }
                     print "\" ";
                 }
                 if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                     print "disabled=\"disabled\" ";
                 }
                 if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                     print "class=\"" . $this->structure[$fieldname]["options"]["css_field_class"] . "\" ";
                 }
                 if (isset($this->structure[$fieldname]["options"]["disabled"])) {
                     if ($this->structure[$fieldname]["options"]["disabled"] == "yes") {
                         print "disabled=\"disabled\" ";
                     }
                 }
                 print "type=\"radio\" style=\"border: 0px\" name=\"{$fieldname}\" value=\"{$value}\" id=\"" . $fieldname . "_" . $value . "\">";
                 print "<label for=\"" . $fieldname . "_" . $value . "\">" . $translations[$value] . "</label><br>";
             }
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         case "checkbox":
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             // render form field
             print "<input ";
             if (isset($this->structure[$fieldname]["defaultvalue"])) {
                 if ($this->structure[$fieldname]["defaultvalue"] == "on" || $this->structure[$fieldname]["defaultvalue"] == "1" || $this->structure[$fieldname]["defaultvalue"] == "enabled") {
                     print "checked ";
                 }
             }
             // if actions enabled, configure all the actions that have been defined
             if (isset($this->actions[$fieldname])) {
                 print "onclick=\"";
                 foreach (array_keys($this->actions[$fieldname]) as $target_field) {
                     if (isset($this->actions[$fieldname][$target_field]["1"])) {
                         $action = $this->actions[$fieldname][$target_field]["1"];
                     }
                     switch ($action) {
                         case "show":
                             print "obj_show('" . $target_field . "'); ";
                             break;
                         case "hide":
                             print "obj_hide('" . $target_field . "'); ";
                             break;
                     }
                 }
                 print "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                 print "disabled=\"disabled\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                 print "class=\"" . $this->structure[$fieldname]["options"]["css_field_class"] . "\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["disabled"])) {
                 if ($this->structure[$fieldname]["options"]["disabled"] == "yes") {
                     print "disabled=\"disabled\" ";
                 }
             }
             print "type=\"checkbox\" style=\"border: 0px\" name=\"" . $fieldname . "\" id=\"" . $fieldname . "\">";
             // post field label
             if (!isset($this->structure[$fieldname]["options"]["nolabel"])) {
                 if (isset($this->structure[$fieldname]["options"]["label"])) {
                     $translation = $this->structure[$fieldname]["options"]["label"];
                 } else {
                     $translation = language_translate_string($this->language, $fieldname);
                 }
                 print "<label for=\"" . $fieldname . "\">" . $translation . "</label>";
             }
             break;
         case "dropdown":
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             /*
             	there are two ways to draw drop down tables:
             	
             	1. Just pass it the array of values, and the code will translate them using the language DB
             
             	2. Pass it an array of translation values with the array keys matching the value names. This
             	   is useful when you want to populate a dropdown with data from a different table.
             */
             // set default size
             if (!isset($this->structure[$fieldname]["options"]["width"])) {
                 $this->structure[$fieldname]["options"]["width"] = 250;
             }
             // create value array if the SQL has not been executed yet
             if (is_string($this->structure[$fieldname]["values"])) {
                 if (!empty($this->structure[$fieldname]["defaultvalue"])) {
                     $query = str_replace("CURRENTID", $this->structure[$fieldname]["defaultvalue"], $this->structure[$fieldname]["values"]);
                 } else {
                     $query = str_replace("CURRENTID", "0", $this->structure[$fieldname]["values"]);
                 }
                 $this->structure[$fieldname]["values"] = array();
                 $sql_obj = new sql_query();
                 $sql_obj->string = $query;
                 $sql_obj->execute();
                 if ($sql_obj->num_rows()) {
                     $sql_obj->fetch_array();
                     foreach ($sql_obj->data as $data) {
                         // merge multiple labels into a single label
                         $label = $data["label"];
                         for ($i = 0; $i < count(array_keys($data)); $i++) {
                             if (!empty($data["label{$i}"])) {
                                 $label .= " -- " . $data["label{$i}"];
                             }
                         }
                         // only add an option if there is an id and label for it
                         if ($data["id"] && $label) {
                             $this->structure[$fieldname]["values"][] = $data["id"];
                             $this->structure[$fieldname]["translations"][$data["id"]] = $label;
                         }
                     }
                 } else {
                     print "No " . language_translate_string($_SESSION["user"]["lang"], $fieldname) . " avaliable.";
                     print "<input type=\"hidden\" name=\"{$fieldname}\" value=\"" . "No " . language_translate_string($_SESSION["user"]["lang"], $fieldname) . " avaliable." . "\">";
                     break;
                 }
             }
             if (isset($this->structure[$fieldname]["translations"])) {
                 $translations = $this->structure[$fieldname]["translations"];
             } else {
                 // get translation for all options
                 $translations = language_translate($this->language, $this->structure[$fieldname]["values"]);
             }
             // input box for filtering
             if (isset($this->structure[$fieldname]["options"]["search_filter"])) {
                 // subtact filter width from form element width
                 $width_filter = 100;
                 // px
                 $width_element = $this->structure[$fieldname]["options"]["width"];
                 // total
                 $this->structure[$fieldname]["options"]["width"] = $width_element - $width_filter;
                 // write filter field
                 print "<input id=\"_" . $fieldname . "\" class=\"dropdown_filter\" style=\"width:" . $width_filter . "px\"";
                 if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                     print "disabled=\"disabled\" ";
                 }
                 print "/>&nbsp;";
             }
             // start dropdown/select box
             print "<select name=\"{$fieldname}\" size=\"1\" style=\"width: " . $this->structure[$fieldname]["options"]["width"] . "px;\"";
             if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                 print "disabled=\"disabled\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                 print "class=\"" . $this->structure[$fieldname]["options"]["css_field_class"] . "\" ";
             }
             print "> ";
             // if there is only 1 option avaliable, see if we should auto-select it.
             if (!empty($this->structure[$fieldname]["options"]["noselectoption"])) {
                 $this->structure[$fieldname]["options"]["autoselect"];
                 log_write("warning", "inc_forms", "obsolete usage of noselectoption dropdown option for field {$fieldname}");
             }
             if (!empty($this->structure[$fieldname]["options"]["autoselect"]) && !empty($this->structure[$fieldname]["values"])) {
                 if (count($this->structure[$fieldname]["values"]) == 1) {
                     $autoselect = 1;
                 }
             }
             // if there is no current entry, add a select entry as default
             if ((!isset($this->structure[$fieldname]["defaultname"]) || $this->structure[$fieldname]["defaultname"] == null) && (!isset($autoselect) || $autoselect == null)) {
                 print "<option value=\"\">-- select --</option>";
             }
             //echo "</select>";
             // add all the options
             foreach ($this->structure[$fieldname]["values"] as $value) {
                 print "<option ";
                 // is the current row, the one that is in use? If so, add the 'selected' tag to it
                 if (isset($this->structure[$fieldname]["defaultvalue"]) && $value == $this->structure[$fieldname]["defaultvalue"]) {
                     print "selected='selected' ";
                 }
                 print "value=\"{$value}\">" . $translations[$value] . "</option>";
             }
             // end of select/drop down
             print "</select>";
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         case "submit":
             $translation = language_translate_string($this->language, $this->structure[$fieldname]["defaultvalue"]);
             print "<input name=\"{$fieldname}\" type=\"submit\" value=\"{$translation}\"";
             if (isset($this->structure[$fieldname]["options"]["disabled"])) {
                 if ($this->structure[$fieldname]["options"]["disabled"] == "yes") {
                     print "disabled=\"disabled\" ";
                 }
             }
             print ">";
             break;
         case "message":
             // sometimes message data is coming directly out of the SQL database, we should run HTML entities
             // conversion on it.
             $this->structure[$fieldname]["defaultvalue"] = nl2br($this->structure[$fieldname]["defaultvalue"]);
             //$this->structure[$fieldname]["defaultvalue"]	= htmlentities($this->structure[$fieldname]["defaultvalue"]);
             print $this->structure[$fieldname]["defaultvalue"];
             break;
         case "file":
             // get max upload size
             $upload_maxbytes = format_size_human(sql_get_singlevalue("SELECT value FROM config WHERE name='UPLOAD_MAXBYTES'"));
             // optional prefix label/description
             if (isset($this->structure[$fieldname]["options"]["prelabel"])) {
                 print $this->structure[$fieldname]["options"]["prelabel"];
             }
             // input field
             print "<input type=\"file\" name=\"{$fieldname}\"";
             if (isset($this->structure[$fieldname]["options"]["disabled"]) && $this->structure[$fieldname]["options"]["disabled"] == "yes") {
                 print "disabled=\"disabled\" ";
             }
             if (isset($this->structure[$fieldname]["options"]["css_field_class"])) {
                 print "class=\"" . $this->structure[$fieldname]["options"]["css_field_class"] . "\" ";
             }
             print "> <i>Note: File must be no larger than {$upload_maxbytes}.</i>";
             // optional label/description
             if (isset($this->structure[$fieldname]["options"]["label"])) {
                 print "<label for=\"" . $fieldname . "\">" . $this->structure[$fieldname]["options"]["label"] . "</label>";
             }
             break;
         default:
             log_debug("form", "Error: Unknown field type of " . $this->structure["fieldname"]["type"] . "");
             break;
     }
     return 1;
 }
Пример #5
0
 function verify_upload_form($fieldname, $acceptable_formats = NULL)
 {
     log_write("debug", "file_storage", "Executing verify_upload_form({$fieldname}, Array)");
     // make sure a file has been provided.
     if (!$_FILES[$fieldname]['size']) {
         // no file provided - maybe it hit the PHP max?
         switch ($_FILES[$fieldname]["error"]) {
             case UPLOAD_ERR_INI_SIZE:
                 log_write("error", "file_storage", "File upload was in excess of maximum PHP limit of " . ini_get('upload_max_filesize') . "");
                 break;
             case UPLOAD_ERR_NO_FILE:
                 log_write("error", "file_storage", "No file supplied for upload.");
                 break;
             default:
                 log_write("error", "file_storage", "Unexpected upload error: " . $_FILES[$fieldname]["error"] . "");
                 break;
         }
         // return failure
         $_SESSION["error"]["{$fieldname}-error"] = 1;
         return 0;
     }
     // check the filesize is less than or equal to the max upload size
     if ($_FILES[$fieldname]['size'] >= $this->config["upload_maxbytes"]) {
         $filesize_max_human = format_size_human($this->config["upload_maxbytes"]);
         $filesize_upload_human = format_size_human($_FILES[$fieldname]['size']);
         log_write("error", "file_storage", "Files must be no larger than {$filesize_max_human}. You attempted to upload a {$filesize_upload_human} file.");
         $_SESSION["error"]["{$fieldname}-error"] = 1;
         return 0;
     }
     // check if the upload format is acceptable
     if ($acceptable_formats) {
         if (!in_array(format_file_extension($_FILES[$fieldname]["name"]), $acceptable_formats)) {
             log_write("error", "file_storage", "Unsupported file format, only the following file formats are acceptable: " . format_arraytocommastring($acceptable_formats));
             $_SESSION["error"]["{$fieldname}-error"] = 1;
             return 0;
         }
     }
     // no problems
     return 1;
 }