Beispiel #1
0
function smarty_block_form($p, $content, Smarty_Internal_Template $template, &$repeat = false)
{
    // only output on the closing tag
    if (!$repeat) {
        $smarty = $template->smarty;
        // look up form data
        BF::load_module('BF_form');
        $form = gform(isset($smarty->_tag_stack[0][1]['data']) ? $smarty->_tag_stack[0][1]['data'] : null);
        if (!isset($p['method'])) {
            $p['method'] = $form->method;
        }
        if (!isset($p['id']) && isset($p['name'])) {
            $p['id'] = $p['name'];
        }
        if (!isset($p['enctype']) && $form->enctype) {
            $p['enctype'] = $form->enctype;
        }
        // if enctype is 'file' alias
        if (isset($p['enctype']) && $p['enctype'] == 'file') {
            $p['enctype'] = "multipart/form-data";
        }
        // set url
        $html = "<form" . $smarty->attr('action', $smarty->make_url(isset($p["href"]) ? $p["href"] : false, isset($p["locale"]) ? $p["locale"] : null));
        foreach ($p as $key => $val) {
            if ($key == 'action' || $key == 'data') {
                continue;
            }
            $html .= $smarty->attr($key, $val);
        }
        return $html . ">" . $content . "</form>";
    }
}
Beispiel #2
0
 public static function check($password)
 {
     if (isset($_SESSION["_simple_password_md5"]) && $_SESSION["_simple_password_md5"] == md5($password)) {
         return true;
     }
     if (isset($_POST["_simple_password"]) && md5($_POST["_simple_password"]) == md5($password)) {
         $_SESSION["_simple_password_md5"] = md5($_POST["_simple_password"]);
         return true;
     }
     BF::load_module("BF_output_template");
     $tpl = new BF_output_template("simple_password");
     $tpl->disp();
     die;
 }
Beispiel #3
0
 public function display($callback = null)
 {
     // clean buffer in case a buffer was active
     @ob_end_clean();
     try {
         if ($callback == null) {
             BF::load_module("BF_output_template");
             $tpl = new BF_output_template();
             $callback = array($tpl, "show_error");
         }
         call_user_func($callback, $this->display['type'], $this->display['message'], $this->display['title'], BF::gc('error_debug') ? $this->debug_html : null);
     } catch (exception $new_e) {
         // if fails, then just show a basic html page
         @header('Content-type: text/html');
         print "<html><body><div><h1>" . $this->display['title'] . "</h1><br/>" . $this->display['message'] . ($this->debug_html && BF::gc('error_debug') ? "<br/><br/><pre>" . $this->debug_html . "</pre>" : "") . "</div></body></html>";
         die;
     }
 }
Beispiel #4
0
<?php

/*-------------------------------------------------------*\
|  PhpBF                                                  |
|  License: LGPL, see LICENSE                             |
\*-------------------------------------------------------*/
/**
* MySQL DB module
* @file BF_DB_mysql.php
* @package PhpBF
* @subpackage database_mysql
* @version 0.7
* @author Loic Minghetti
* @date Started on the 2007-08-18
*/
BF::load_module("BF_DB");
/**
 * Class to access mysql database
 */
class BF_DB_mysql extends BF_DB
{
    private $link;
    private $last_result;
    public $num_queries = 0;
    public function __construct($db, $host = null, $user = null, $password = null)
    {
        $this->link = @mysql_pconnect($host, $user, $password);
        if ($this->link) {
            if (!@mysql_select_db($db)) {
                @mysql_close($this->link);
                $this->link = NULL;
Beispiel #5
0
    }
    BF::load_module("BF_output_template");
    $tpl = new BF_output_template("view_car");
    $tpl->assign('car', $car);
    $tpl->disp();
} elseif ($action == "save") {
    BF::load_module("BF_form");
    $form = new BF_form('edit_car');
    $car = new car($id);
    if (!$car->exists()) {
        throw new BF_not_found();
    }
    // check
    if (!$form->check()) {
        $form->show_error();
    }
    // process
    $car->name = $form->gval("name");
    $car->price = $form->gval("price");
    $car->save();
    // redirect
    BF::gr("example")->redirect();
} else {
    // list all cars from db
    $list = BF::glist('car');
    // display
    BF::load_module("BF_output_template");
    $tpl = new BF_output_template("list_cars");
    $tpl->assign('list', $list);
    $tpl->disp();
}
Beispiel #6
0
|  License: LGPL, see LICENSE                             |
\*-------------------------------------------------------*/
/**
* Output plain text module
* @file output.plain.php
* @package PhpBF
* @subpackage plain_output
* @version 0.7
* @author Loic Minghetti
* @date Started on the 2008-07-10
*/
// Security
if (!defined('C_SECURITY')) {
    exit;
}
BF::load_module("BF_output");
/**
 * Class interface for all output modules
 */
class BF_output_plain
{
    function __construct()
    {
        BF::register_error_output_callback(array($this, "show_error"));
    }
    /**
     * @var 	string	$default_content_type : Content_type to use by defult
     */
    public $content_type = 'text/plain';
    /**
     * Show an error using this output module
Beispiel #7
0
<?php

/**
* @file BF_user_abstract.php
*/
BF::load_module('BF_record');
abstract class BF_user_abstract extends BF_record
{
    /**
     * Function to check if a user is logged in and return a user object of the logged user
     * @return	user object or false if no user session could be found
     * @warning	BF:gu() will  call this function, prefere using BF::gu() to get currently logged user
     */
    public static function get_logged_user()
    {
        if (!isset($_SESSION['BF_' . BF::gc('project_id') . '_logged_id_user'])) {
            return false;
        }
        $user = new user($_SESSION['BF_' . BF::gc('project_id') . '_logged_id_user']);
        if (!$user->is_logged()) {
            return false;
        }
        return $user;
    }
    /**
     * Load user data by giving it's username
     * @param	string	$username : Load user given value of the username field
     */
    public static function get_by_username($username)
    {
        $result = BF::glist("user", user::$username_field . " = " . Q($username, "user"));
Beispiel #8
0
 /**
  * Reset user password and send by email
  */
 public function send_password()
 {
     /**
      * Example 
      */
     BF::load_module('BF_mail');
     BF::load_module("BF_output_template");
     $tpl = new BF_output_template('mail_user_password');
     $user =& $this;
     $tpl->assign('user', $user);
     $tpl->assign('password', $this->reset_password());
     $mail = new BF_mail();
     $mail->From = BF::gu()->_email;
     $mail->FromName = BF::gu()->_username;
     $mail->AddReplyTo($mail->From, $mail->FromName);
     $mail->AddAddress($this->_email);
     $mail->Body = $tpl->disp(false);
     $mail->Subject = $tpl->get_template_vars('subject');
     if ($mail->send()) {
         return true;
     } else {
         throw new exception('Failed sending password mail');
     }
 }
Beispiel #9
0
function smarty_function_input($p, Smarty_Internal_Template $template)
{
    $smarty = $template->smarty;
    BF::load_module('BF_form');
    // Determine input ID and field name
    if (!isset($p['id']) || $p['id'] == '') {
        static $counter = 0;
        $id = $p['id'] = 'input_unnamed_' . ++$counter;
    } else {
        $id = $p['id'];
    }
    if (!isset($p['name']) || $p['name'] == '') {
        $name = $p['name'] = $p['id'];
    } else {
        $name = $p['name'];
    }
    // Load form data from <form> tag, or from a given form_data
    if (isset($p['form_data'])) {
        $form = gform($p['form_data']);
    } else {
        for ($i = count($smarty->_tag_stack) - 1; $i >= 0; $i--) {
            if ($smarty->_tag_stack[$i][0] == 'form') {
                $form = $smarty->_tag_stack[$i][1]['data'] = gform(isset($smarty->_tag_stack[$i][1]['data']) ? $smarty->_tag_stack[$i][1]['data'] : null);
                break;
            }
        }
    }
    if (!isset($form)) {
        $form = gform();
    }
    // if no forms were found, then juste create a new form object
    // properties set as parmeters and not in the properties array should be appended
    foreach ($p as $param => $value) {
        if (in_array($param, BF_form::$properties)) {
            $p['properties'][$param]['value'] = $value;
            // see if there are any default invalid message to display
            if (BF::gc('locale_enabled') && BF::gl()->block_exists('form.error_' . $param)) {
                $p['properties'][$param]['invalid_message'] = BF::gl()->tl_tag('form.error_' . $param . '|' . $value . '|' . ucfirst(isset($p['title']) ? $p['title'] : ($form->get_title($name) ? $form->get_title($name) : (isset($p['alt']) ? $p['alt'] : $name))));
            }
            unset($p[$param]);
        }
    }
    // get data from field and append passed properties and options
    $field =& $form->get_field($name);
    // mix prameters and field data, parameters override field data
    if (isset($p['properties']) && is_array($p['properties'])) {
        $field['properties'] = array_merge(isset($field['properties']) && is_array($field['properties']) ? $field['properties'] : array(), $p['properties']);
    }
    if (isset($p['options']) && is_array($p['options'])) {
        $field['options'] = array_merge(isset($field['options']) && is_array($field['options']) ? $field['options'] : array(), $p['options']);
    }
    $p = array_merge($field, $p);
    $p['properties'] =& $form->get_properties($name);
    $p['options'] =& $form->get_options($name);
    // get input type
    $type = isset($p['type']) ? $p['type'] : 'text';
    // if file input, set form enctype to multipart, if not already set
    if ($type == 'file' && !$form->enctype) {
        $form->enctype = 'file';
    }
    // if using max length, then add the html MAXLENGTH attribut too
    if ($form->get_property($name, 'max_length') > 0) {
        $maxlength = $form->get_property($name, 'max_length');
        $p['maxlength'] = $maxlength['value'];
    }
    // see if input is disabled or checked
    if (array_key_exists('disabled', $p)) {
        if ($p['disabled']) {
            $p['disabled'] = 'disabled';
        } else {
            unset($p['disabled']);
        }
    }
    if (array_key_exists('readonly', $p)) {
        if ($p['readonly']) {
            $p['readonly'] = 'readonly';
        } else {
            unset($p['readonly']);
        }
    }
    if (array_key_exists('checked', $p)) {
        if ($p['checked']) {
            $p['checked'] = 'checked';
        } else {
            unset($p['checked']);
        }
    }
    if (array_key_exists('multiple', $p)) {
        if ($p['multiple']) {
            $p['multiple'] = 'multiple';
        } else {
            unset($p['multiple']);
        }
    }
    // init the output string
    $html = "";
    // compute options list for iselect/select/radioset
    if ($type == 'select' || $type == 'iselect' || $type == 'radioset') {
        $options_html = '';
        $selected_option = false;
        if ($type == 'iselect') {
            $options_html .= "<div" . $smarty->attr('id', $id . '_iselect_div') . $smarty->attr('class', 'input_iselect_list') . ">";
        }
        if (isset($p['options']) && is_array($p['options'])) {
            foreach ($p['options'] as $option) {
                if (!is_array($option)) {
                    $option = array('value' => $option);
                }
                if (!isset($option['value'])) {
                    $option['value'] = '';
                }
                if (!isset($option['text'])) {
                    $option['text'] = isset($option['label']) ? $option['label'] : $option['value'];
                }
                if (isset($option['selected']) && $option['selected'] || isset($option['checked']) && $option['checked'] || isset($p['value']) && (string) $p['value'] === (string) $option['value'] && !$selected_option) {
                    if ($type == 'radioset') {
                        $option['checked'] = 'checked';
                    } else {
                        $option['selected'] = 'selected';
                    }
                    $p['value'] = $option['value'];
                    if ($type != 'select' || !isset($p['multiple'])) {
                        $selected_option =& $option;
                    }
                    // save selected option, so that we don't select followings options that have the same value
                } else {
                    unset($option['selected'], $option['checked']);
                }
                if (isset($option['disabled']) && $option['disabled']) {
                    $option['disabled'] = 'disabled';
                } else {
                    unset($option['disabled']);
                }
                if ($type == 'iselect') {
                    $options_html .= '<a';
                } else {
                    if ($type == 'select') {
                        $options_html .= '<option';
                    } else {
                        if ($type == 'radioset') {
                            $option['class'] = 'input input_radio' . (isset($option['class']) ? ' ' . $option['class'] : '');
                            $options_html .= '<label><input type="radio"' . $smarty->attr('name', $name) . (isset($p["onchange"]) ? $smarty->attr('onchange', $p["onchange"]) : "") . (isset($p["onclick"]) ? $smarty->attr('onclick', $p["onclick"]) : "");
                        }
                    }
                }
                foreach ($option as $key => $val) {
                    if ($key != 'text' && $key != 'label') {
                        $options_html .= $smarty->attr($key, $val);
                    }
                }
                if ($type == 'iselect') {
                    $options_html .= '>' . $option['text'] . '</a>';
                } elseif ($type == 'select') {
                    $options_html .= '>' . $option['text'] . '</option>';
                } elseif ($type == 'radioset') {
                    $options_html .= '/>' . $option['text'] . '</label>';
                }
            }
        }
        if ($type == 'iselect' || $type == 'radioset') {
            unset($p["onchange"], $p["onclick"]);
        }
        if ($type == 'iselect') {
            // if type is iselect, print options now and change type to normal text or hidden
            $html .= $options_html . '</div>';
            // by default, an iselect should be an hidden field, but it may also be a text field
            $type = $form->has_property($name, 'editable') ? 'text' : 'hidden';
            // set the iselect property
            $p['properties']['iselect'] = array('value' => $id . '_iselect_div');
        }
    }
    // append common class names
    $p['class'] = 'input input_' . $type . (isset($p['class']) ? ' ' . $p['class'] : '');
    // open html tag
    if ($type == 'textarea' || $type == 'button' || $type == 'select') {
        $html .= "<" . $type;
    } elseif ($type == 'radioset') {
        $html .= "<div";
    } else {
        $html .= "<input" . $smarty->attr('type', $type);
    }
    // append all other params
    $reserved = array('properties', 'options', 'label', 'type', 'form_data');
    if ($type == 'textarea') {
        $reserved[] = 'value';
    }
    //if ($type == 'checkbox' && isset($p['value']) && !isset($p['checked'])) {
    //	if ($p['value']) $p['checked'] = 'checked';
    //}
    foreach ($p as $key => $val) {
        if ($key != '' && !in_array($key, $reserved)) {
            $html .= $smarty->attr($key, $val);
        }
    }
    // close tag
    if ($type == 'textarea') {
        $html .= ">" . htmlspecialchars(isset($p['value']) ? $p['value'] : '', ENT_COMPAT, BF::$encoding) . "</textarea>";
    } elseif ($type == 'button') {
        $html .= ">" . htmlspecialchars(isset($p['label']) ? $p['label'] : (isset($p['value']) ? $p['value'] : ''), ENT_COMPAT, BF::$encoding) . "</button>";
    } elseif ($type == 'select') {
        $html .= ">" . $options_html . "</select>";
    } elseif ($type == 'radioset') {
        $html .= ">" . $options_html . "</div>";
    } else {
        $html .= " />";
    }
    // print label for radio, checkbox, etc...
    if (isset($p['label']) && $p['label'] != '') {
        $html .= '<label' . $smarty->attr('for', $id) . '>' . $p['label'] . '</label>';
    }
    // if there are at least one property
    if (count($p['properties'])) {
        // load js file if it is the first time a field requires such options
        /*static $js_loaded;
        		if (!$js_loaded) {
        			$html .= $smarty->tpl_js(Array(), 'if (window.Prototype == undefined) document.write('.str_replace('/', '\\/', Q($smarty->tpl_js(Array('src' => "lib/prototype.js"), '', $smarty))).');', $smarty);
        			$html .= $smarty->tpl_js(Array(), 'if (window.advancedFormControl == undefined) document.write('.str_replace('/', '\\/', Q($smarty->tpl_js(Array('src' => "form.js"), '', $smarty))).');', $smarty);
        			// Note : Of script is loaded that way, then it might not be laoded yet when next line is executed
        			//$html .= $smarty->tpl_js(Array(), 'if (window.advancedFormControl == undefined) document.getElementsByTagName("head")[0].appendChild(new Element("script", {type: "text/javascript", src: "'.gf('js')->web_path.'form.js"}));', $smarty);
        			$js_loaded = true;
        		}*/
        BF::gr("/tags/block.js.php")->load_once();
        $load_js = smarty_block_js(array('src' => "lib/form.js"), "", $template);
        $html .= smarty_block_js(array(), 'if (afcUtils == undefined) document.write(' . str_replace('/', '\\/', Q($load_js)) . ');', $template);
        $html .= smarty_block_js(array(), $form->get_js($name, $id), $template);
    }
    return $html;
}
Beispiel #10
0
 /**
  * Load current locale object
  * @warning	lang code should always be in lower case, while country code in uper case
  * @return	locale object
  */
 public static function gl($locale_string = '')
 {
     static $locale = null;
     if ($locale == null) {
         if (BF::gc('locale_enabled')) {
             BF::load_module('locale');
             $locale = new BF_locale();
         } else {
             $locale = new BF_locale_disabled();
         }
     }
     return $locale;
 }
Beispiel #11
0
/*-------------------------------------------------------*\
|  PHP BasicFramework - Ready to use PHP site framework   |
|  License: LGPL, see LICENSE                             |
\*-------------------------------------------------------*/
/**
* Database module
* @file BF_DB_inerface.php
* @package PhpBF
* @subpackage database
* @version 0.7
* @author Loic Minghetti
* @date Started on the 2008-01-09
* @comment These classes were originaly placed in framework.php and later generic.php
*/
BF::load_module("BF_DB_interface");
abstract class BF_DB implements BF_DB_interface
{
    public function get_query($query)
    {
        $result = $this->query($query);
        $rows = array();
        while ($row = $this->fetch_array($result)) {
            $rows[] = $row;
        }
        return $rows;
    }
    public function get_first($query)
    {
        $result = $this->get_query($query);
        if (count($result) == 0) {
Beispiel #12
0
if (!test::framework_working()) {
    print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;There are issues with current server configuration. Read above for more info. You can test framework and database connections once all requirements are fulfilled.';
} else {
    require get_file("framework", "framework.php")->get_path();
    print '&nbsp;&nbsp;&nbsp;&nbsp;If you see no error above, then include was ' . test::ok("successful") . '
	<h3>Initializing framework</h3>';
    BF::init();
    print '&nbsp;&nbsp;&nbsp;&nbsp;If you see no error above, then initialization was ' . test::ok("successful") . '
	<h3>Database connexions</h3>';
    if (count(test::dbconnections()) > 0) {
        print '<table cellspacing="0" cellpadding="5" class="tests"><tr>';
        foreach (test::dbconnections() as $id => $data) {
            $error = false;
            try {
                BF::load_module("database");
                BF::load_module("database." . $data[0]);
                $class = "BF_DB_" . $data[0];
                if (!call_user_func(array($class, "supported"))) {
                    throw new exception($data[0] . " is not supported by your PHP server");
                }
                $db = BF::gdb($id);
            } catch (exception $e) {
                $error = $e->getMessage();
            }
            print '
			<tr>
				<td class="title"><b>ID: ' . $id . '</b>&nbsp;&nbsp;&nbsp;(' . implode(", ", $data) . ')</td>
				<td>' . ($error ? test::invalid($error) : test::ok()) . '</td>
			</tr>';
        }
        print '</table>';