PHP Classes
elePHPant
Icontem

reconfig: Get configuration from files, pages and databases

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2015-01-30 (7 months ago) RSS 2.0 feedNot enough user ratingsTotal: 426 This week: 1All time: 5,871 This week: 1,053Up
Version License PHP version Categories  
reconfig 5GNU General Publi...5.0.0PHP 5, Databases, Files and Folders, C...
Description Author  

This package can get configuration from files, pages and databases.

The main class can get input data from files, remote site pages, a database or the result of execution of given PHP code.

The class can extract values from the input data using regular expressions or custom PHP code and saves it to files or a database.

Currently it supports MySQL, PostgreSQL and Microsoft SQL server databases.

Picture of giuseppe lucarelli
Name: giuseppe lucarelli <contact>
Classes: 5 packages by
Country: Italy Italy
Age: 56
All time rank: 84434 in Italy Italy
Week rank: 394 Up22 in Italy Italy Up
Innovation award
Innovation award
Nominee: 2x

Details provided by the author  
This program can read/write input/output data from/to database or text files, like static web pages,
and extract data with regular expression. Mysql/mysqli, postgresql and mssql server databases are
supported.
I'm sorry but this is a very little program explanation. You better understand with examples.
Download at:
http://digiteca.bsmc.it/reconfig/example.zip

example/bibris/index.html    (running at http://digiteca.bsmc.it)
    controller.php
    detail.php
    search.php
    advsearch.php

example/percor/index.html    (for managing web page
    controller.php            http://www.bsmc.it/modules.php?name=Content&pa=showpage&pid=40)
                             (install or view at http://digiteca.bsmc.it/reconfig/example/percor)

example/bsmc/log.html        (for managing varius log files)
    controller.php           (install or view at http://digiteca.bsmc.it/reconfig/bsmc/log.html)

example/storia/index.html    (for managing right block named "incontri di storia" at http://bsmc.it)
    controller.php           (install or view at http://digiteca.bsmc.it/reconfig/example/storia)

example/pop3ml/index.html    (for managing "pop3ml" mailing list manager installation)
    controller.php           (install or view at http://digiteca.bsmc.it/reconfig/example/pop3ml)
example/pop3ml/viewmsg.html  (for viewing "pop3ml" mailing list manager installation email messages)
    vmcontroller.php         (only view at
                              http://digiteca.bsmc.it/reconfig/example/pop3ml/viewmsg.html)
example/pop3ml/test_pop3ml.html (for testing "pop3ml" mailing list class)
    vmcontroller.php         (install or view with limited functionality at
                              http://digiteca.bsmc.it/reconfig/example/pop3ml/test_pop3ml.html)


this class works with jquery.reconfig-1.0.js, a jquery plugin. for example:

<html>
<head>
<SCRIPT LANGUAGE="JavaScript" SRC="js/jquery-1.6.2.min.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="js/jquery.reconfig-1.0.js"></SCRIPT>
<SCRIPT TYPE="text/javascript">
var $reconfig={
    init: function () {
        $.reconfig.defaults = $.extend($.reconfig.defaults,this.settings);
    },
    settings: {
        auth_host: 'localhost',
        auth_user: 'demo',
        auth_pass: 'demo',
        lang: 'en',
        items: null,
        controller: 'controller.php',
        language: null
    }
};
// if there is no 'target' option use '$reconfig' var for input/output object
$(document).ready(function() {
    $('#building').reconfig({action: ['login','build']});
</SCRIPT>
<BODY>
<div id="building">
</BODY>
</HTML>



EXAMPLES:

extracting data from a xml file:
-------------------------------

<?xml version="1.0" encoding="iso-8859-1"?>
<glz:Config>
        <glz:Import src="MWCMS_info.xml" />
        <glz:Param name="DATASOURCE_MODE" value="db" />
        <glz:Param name="DB_HOST" value="localhost" />
        <glz:Param name="DB_NAME" value="cms_test" />
        <glz:Param name="DB_USER" value="user" />
        <glz:Param name="DB_PSW" value="" />
        <glz:Param name="DB_PREFIX" value="cms_" />
        <glz:Param name="SMTP_HOST" value="hostme" />
        <glz:Param name="SMTP_USER" value="admin" />
        <glz:Param name="SMTP_PSW" value="1234" />
        <glz:Param name="SMTP_SENDER" value="MIBAC" />
        <glz:Param name="SMTP_EMAIL" value="me@me.com" />
        <glz:Param name="START_PAGE" value="1" />
        <glz:Param name="SEF_URL" value="true" />
        <glz:Param name="CACHE_CODE" value="-1" />
        <glz:Param name="PSW_METHOD" value="" />
        <glz:Param name="DEBUG" value="false" />
        <glz:Param name="USER_DEFAULT_ACTIVE_STATE" value="1" />
</glz:Config>

example of php code (controller.php):

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->auth='none';     // 'httpHeader';  'sql';
    $HTML = array(
        'building'=>array(
            array('type'=>'input','name'=>'db_name','label'=>'db name',
                'in'=>array('type'=>'file','path'=>'config.xml',
                    'regexp'=>array(array('pattern'=>"/(?:[[:space:]]+|)<glz:Param name=['\"]DB_NAME['\"] value=[\"'](.*)[\"'](?:\s+|)\/>/imU"))),
                'out'=>array('type'=>'file','path'=>'config.xml',
                    'regexp'=>array(array('pattern'=>"/(.*(?:[[:space:]]+|)<glz:Param name=['\"]DB_NAME['\"] value=[\"'])(.*)([\"'].*Config>$)/imsU")))),
            array('type'=>'input','name'=>'db_user','label'=>'db user',
                'in'=>array('regexp'=>array(array('pattern'=>"/(?:[[:space:]]+|)<glz:Param name=['\"]DB_USER['\"] value=[\"'](.*)[\"'](?:\s+|)\/>/imU"))),
                'out'=>array('regexp'=>array(array('pattern'=>"/(.*(?:[[:space:]]+|)<glz:Param name=['\"]DB_USER['\"] value=[\"'])(.*)([\"'].*Config>$)/imsU")))),
            array('type'=>'input','name'=>'db_psw','label'=>'db psw',
                'in'=>array('regexp'=>array(array('pattern'=>"/(?:[[:space:]]+|)<glz:Param name=['\"]DB_PSW['\"] value=[\"'](.*)[\"'](?:\s+|)\/>/imU"))),
                'out'=>array('regexp'=>array(array('pattern'=>"/(.*(?:[[:space:]]+|)<glz:Param name=['\"]DB_PSW['\"] value=[\"'])(.*)([\"'].*Config>$)/imsU")))),
           ....
        )
    );
    $REC->Init($HTML['building'],'building');
    echo json_encode($HTML);
?>

Running with javascript code for building:

        var $reconfig = { settings: { lang:'en',language:{...},... }};
        $('#building').reconfig({target:$reconfig,action: ['exec','build'],
            controller:'controller.php',do_after_build:function.....});

'$reconfig.settings.json_data' will be filled with an object like this:
        building=[{name:'db_name',...,values:['cms_test']..},{name:'db_user',...,values:['user'],..}]


Running with javascript code for saving:

        $('#building').reconfig({action:'save','controller':'controller.php',
            json_data: $reconfig.settings.json_data,
            do_after_save: function(data) ....});


simplified example from 'storia', extracting data from a web page of my library web site:
-----------------------------------------------------------------------------------------

<html>
...
<center>
<div class="dtree">
<script>
var eventi = {
'evento1':['31/12/2012 24:00','Agor&agrave; scuola aperta','http://www.agorascuolalaterza.it/programma/','ottobre-novembre 2011<br>Altamura, Bari, Bologna, Corato, Milano, Roma'],
'evento2':['19/12/2011 24:00','Sebben che siamo donne<br>150 anni di lotte e conquiste in Italia','http://www.unitn.it/files/download/18578/sebbenchesiamodonne.pdf','10 ottobre 2011-<br>19 dicembre 2011<br>Trento'],
'evento3':['11/04/2012 24:00','L&rsquo;arte pubblica nel &rsquo;900<br>Il mito dell&rsquo;uomo nuovo','/pdf/FAIappuntamenticonlarte.pdf','12 ottobre 2011-<br>11 aprile 2012<br>Roma'],
'evento4':['11/05/2012 24:00','La fabrication des images de guerres &agrave; l&rsquo;&eacute;poque contemporaine','http://www.oehirom.it/files/Programma%20est..pdf','13 ottobre 2011-<br>11 maggio 2012<br>Bruxelles']
};
...
</script>
...
</html>

controller.php:

<?php
    require_once('class.reconfig.php');
    $HTML = array(
        'building'=>array(
            array('type'=>'select','name'=>'storia','label'=>'incontri di storia','encode'=>false,
                // display: 0=key, 1,2,3,..=first item of values, second,third...
                'label'=>'','display'=>'0',
                'attrs'=>array('size'=>4,'style'=>'width: 100%; height: 100%; overflow: scroll'),
                'in'=>array('type'=>'sql','group'=>'storia',
                    'query'=>'select content from fake_table where bid = 22','column'=>'content',
                    'dbhost'=>'localhost','dbname'=>'fake_db',
                    'dbuser'=>'root','dbpass'=>'',
                    'regexp'=>array(
                        array('pattern'=>"/var eventi = \{(.*)\};[$\r\n]/imsU"),
                        array('key'=>true,'pattern'=>"/.*['\"](.*)['\"]:\[(.*)\](?:,|$)/imsU"),
                        array('pattern'=>"/'(.*)'(?:,|$)/imsU"))),
                'out'=>array('type'=>'sql','group'=>'storia','column'=>'content','target'=>'values',
                    'query'=>'update fake_table set __SET__ where bid = 22',
                    'dbhost'=>'localhost','dbname'=>'fake_db',
                    'dbuser'=>'root','dbpass'=>'',
                    'regexp'=>array(
                        array('pattern'=>"/(.*var eventi = \{)(.*)(\}.*center>)/imsU"),
                        array('key'=>true,'sep'=>',',
                              'pattern'=>"/(.*['\"])(.*)(['\"]:\[)(.*)(\])(?:,|$)/imsU"),
                        array('sep'=>',','pattern'=>"/(')(.*)(')$/ims"))),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\''))
        ),
    ...
    );
    ...
    $REC = new REConfig();
    $REC->Init($HTML['building'],'building');
    echo json_encode($HTML);
?>

$HTML will be set with this values:

Array (
    [building] => Array (
        [0] => Array ( 
            [type] => select
            [name] => storia
            [label] => 
            [encode] => 
            [display] => 0
            [attrs] => Array ( [size] => 4 [style] => width: 100%; height: 100%; overflow: scroll) 
            [event] => Array ( [onchange] => '$reconfig.set_event(event);')
            [values] => Array ( 
                [evento1] => Array ( 
                    [0] => 31/12/2012%2024%3A00
                    [1] => Agor%26agrave%3B%20scuola%20aperta
                    [2] => http%3A//www.agorascuolalaterza.it/programma/
                    [3] => ottobre-novembre%202011%3Cbr%3EAltamura%2C%20Bari%2C%20Bologna%2C%20Corato%2C%20Milano%2C%20Roma
                )       
            [evento2] => Array ( 
                    [0] => 19/12/2011%2024%3A00
                    [1] => Sebben%20che%20siamo%20donne%3Cbr%3E150%20anni%20di%20lotte%20e%20conquiste%20in%20Italia
                    [2] => http%3A//www.unitn.it/files/download/18578/sebbenchesiamodonne.pdf
                    [3] => 10%20ottobre%202011-%3Cbr%3E19%20dicembre%202011%3Cbr%3ETrento
                )       
            ...     
            [eventog] => Array ( 
                    [0] => 25/02/2012%2024%3A00
                    [1] => La%20societ%26agrave%3B%20dello%20sguardo%3Cbr%3ERicerche%20sulla%20storia%20della%20visione%20in%20et%26agrave%3B%20contemporanea%3Cbr%3E%28secc.%20XIX-XX%29
                    [2] => http%3A//sguardo.storia.unipd.it/SguardoITA/Societa_dello_sguardo/Home.html
                    [3] => 23-25%20febbraio%202012%3Cbr%3EPadova
            )))))

USING XML INSTEAD PHP ARRAY FOR $HTML:
--------------------------------------

define('__DRIVER__','mysql');
define('__HOST__','localhost');
define('__DBNAME__','name');
define('__USER__','root');
define('__PASS__','1234');
$cname='constant';
$XML = <<<EOF
<root>
 <authentication>
 </authentication>
 <building>
  <item>
   <type>select</type><name>storia</name><display>1</display>
   <attrs><size>4</size><style>width: 100%; height: 100%; overflow: scroll</style></attrs>
   <in>
    <type>sql</type><group>storia</group>
    <query>select content from fake_blocks where bid = 22</query><column>content</column>
    <driver>{$cname('__DRIVER__')}</driver><dbhost>{$cname('__HOST__')}</dbhost><dbname>{$cname('__DBNAME__')}</dbname><dbuser>{$cname('__USER__')}</dbuser><dbpass>{$cname('__PASS__')}</dbpass>
    <regexp><pattern><![CDATA[/var eventi = Array\((.*)\);[\$[:cntrl:]\+]/imsU]]></pattern></regexp>
    <regexp><pattern><![CDATA[/Array\((.*)\)(?:,|$)/imsU]]></pattern></regexp>
    <regexp><pattern><![CDATA[/'(.*)'(?:,|\$)/imsU]]></pattern></regexp>
   </in>
   <out>
    <type>sql</type><group>storia</group><column>content</column><target>values</target>
    <query>update fake_blocks set __SET__ where bid = 22</query>
    <driver>{$cname('__DRIVER__')}</driver><dbhost>{$cname('__HOST__')}</dbhost><dbname>{$cname('__DBNAME__')}</dbname><dbuser>{$cname('__USER__')}</dbuser><dbpass>{$cname('__PASS__')}</dbpass>
    <regexp><pattern><![CDATA[/(.*var eventi = Array\()(.*)(\);.*center>)/imsU]]></pattern></regexp>
    <regexp><sep>,</sep><pattern><![CDATA[/(.*Array\()(.*)(\))(?:,|\$)/imsU]]></pattern></regexp>
    <regexp><sep>,</sep><pattern><![CDATA[/(')(.*)(')\$/ims]]></pattern></regexp>
   </out>
   <event><onchange>'\$reconfig.set_event(event);'</onchange></event>
  </item>
 </building>
 <eventscounter>
  <item>
   <type>input</type><name>eventscnt</name><label>eventi</label>
   <in>
    <type>file</type><path>/tmp/storia.log</path>
    <func>if(strlen(\$data) == 0) \$data="starting storia log\n";</func>
   </in>
   <out>
    <type>file</type><path>/tmp/storia.log</path>
    <func>\$value = \$data.\$this->LogCommand(\$value);</func>
   </out>
  </item>
 </eventscounter>
</root>
EOF;
$HTML=$REC->XmlConvert($XML);
....

different way to write the previous code:
----------------------------------------

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources = array('building'=>array(
        'in'=>array('type'=>'sql',
            'query'=>'select content from fake_table where bid = 22','column'=>'content',
            'dbhost'=>'localhost','dbname'=>'fake_db',
            'dbuser'=>'root','dbpass'=>'',
            'regexp'=>array(
                array('pattern'=>"/var eventi = \{(.*)\};[$\r\n]/imsU"))),
        'out'=>array('type'=>'sql','column'=>'content','target'=>'values',
            'query'=>'update fake_table set __SET__ where bid = 22',
            'dbhost'=>'localhost','dbname'=>'fake_db',
            'dbuser'=>'root','dbpass'=>'',
            'regexp'=>array(
                array('pattern'=>"/(.*var eventi = \{)(.*)(\}.*center>)/imsU"))))
    );

    $HTML = array(
        'building'=>array(
            array('type'=>'select','name'=>'storia','label'=>'incontri di storia','encode'=>false,
                'label'=>'','display'=>'0',
                'attrs'=>array('size'=>4,'style'=>'width: 100%; height: 100%; overflow: scroll'),
                'in'=>array('depth'=>2,
                    'regexp'=>array(
                        array('key'=>true,'pattern'=>"/.*['\"](.*)['\"]:\[(.*)\](?:,|$)/imsU"),
                        array('pattern'=>"/'(.*)'(?:,|$)/imsU"))),
                'out'=>array('target'=>'values',
                    'regexp'=>array(
                        array('key'=>true,'sep'=>',',
                              'pattern'=>"/(.*['\"])(.*)(['\"]:\[)(.*)(\])(?:,|$)/imsU"),
                        array('sep'=>',','pattern'=>"/(')(.*)(')$/ims"))),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\''))
        )
    );

    $REC->Init($HTML['building'],'building');
    echo json_encode($HTML);


a third way to write the previous code:

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources = array('building'=>array(
        'in'=>array('type'=>'sql','depth'=>2,
            'query'=>'select content from fake_table where bid = 22','column'=>'content',
            'dbhost'=>'localhost','dbname'=>'fake_db',
            'dbuser'=>'root','dbpass'=>'',
            'regexp'=>array(
                array('pattern'=>"/var eventi = \{(.*)\};[$\r\n]/imsU"),
                array('key'=>true,'pattern'=>"/.*['\"](.*)['\"]:\[(.*)\](?:,|$)/imsU"),
                array('pattern'=>"/'(.*)'(?:,|$)/imsU"))),
        'out'=>array('type'=>'sql','column'=>'content','target'=>'values',
            'query'=>'update fake_table set __SET__ where bid = 22',
            'dbhost'=>'localhost','dbname'=>'fake_db',
            'dbuser'=>'root','dbpass'=>'',
            'regexp'=>array(
                array('pattern'=>"/(.*var eventi = \{)(.*)(\}.*center>)/imsU"),
                array('key'=>true,'sep'=>',',
                      'pattern'=>"/(.*['\"])(.*)(['\"]:\[)(.*)(\])(?:,|$)/imsU"),
                array('sep'=>',','pattern'=>"/(')(.*)(')$/ims")))
        )
    );

    $HTML = array(
        'building'=>array(
            array('type'=>'select','name'=>'storia','label'=>'incontri di storia','encode'=>false,
                'label'=>'','display'=>'0',
                'attrs'=>array('size'=>4,'style'=>'width: 100%; height: 100%; overflow: scroll'),
                'in'=>array('depth'=>2,'column'=>'content'),
                'out'=>array('target'=>'values','column'=>'content'),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\''))
        )
    );

    $REC->Init($HTML['building'],'building');
    echo json_encode($HTML);


example from 'storia' demo version, extracting data from a text file (storia_demo.html)
-----------------------------------------------------------------------------------------

<?php
    require_once('class.reconfig.php');
    $HTML = array(
        'building'=>array(
            array('type'=>'select','name'=>'storia','label'=>'incontri di storia',
                'encode'=>false,'label'=>'','display'=>'0',
                'attrs'=>array('size'=>4,'style'=>'width: 100%; height: 100%; overflow: scroll'),
                'in'=>array('type'=>'file','path'=>'storia_demo.html',
                    'regexp'=>array(
                        array('pattern'=>"/var eventi = \{(.*)\};[$\r\n]/imsU"),
                        array('key'=>true,'pattern'=>"/.*['\"](.*)['\"]:\[(.*)\](?:,|$)/imsU"),
                        array('pattern'=>"/'(.*)'(?:,|$)/imsU"))),
                'out'=>array('type'=>'file','path'=>'storia_demo.html','target'=>'values',
                    'regexp'=>array(
                        array('pattern'=>"/(.*var eventi = \{)(.*)(\}.*center>)/imsU"),
                        array('key'=>true,'sep'=>',',
                              'pattern'=>"/(.*['\"])(.*)(['\"]:\[)(.*)(\])(?:,|$)/imsU"),
                        array('sep'=>',','pattern'=>"/(')(.*)(')$/ims"))),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\''))
        )
    );
    $REC->Init($HTML['building'],'building');
    echo json_encode($HTML);


different way to write the previous code:

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources = array('building'=>array(
        'in'=>array('type'=>'file','path'=>'storia_demo.html',
            'regexp'=>array(
                array('pattern'=>"/var eventi = \{(.*)\};[$\r\n]/imsU"))),
        'out'=>array('type'=>'file','path'=>'storia_demo.html','target'=>'values',
            'regexp'=>array(
                array('pattern'=>"/(.*var eventi = \{)(.*)(\}.*center>)/imsU"))))
    );
    $HTML = array(
        'building'=>array(
            array('type'=>'select','name'=>'storia','label'=>'incontri di storia',
                'encode'=>false,'label'=>'','display'=>'0',
                'attrs'=>array('size'=>4,'style'=>'width: 100%; height: 100%; overflow: scroll'),
                'in'=>array('depth'=>2,
                    'regexp'=>array(
                        array('key'=>true,'pattern'=>"/.*['\"](.*)['\"]:\[(.*)\](?:,|$)/imsU"),
                        array('pattern'=>"/'(.*)'(?:,|$)/imsU"))),
                'out'=>array('target'=>'values',
                    'regexp'=>array(
                        array('key'=>true,'sep'=>',',
                              'pattern'=>"/(.*['\"])(.*)(['\"]:\[)(.*)(\])(?:,|$)/imsU"),
                        array('sep'=>',','pattern'=>"/(')(.*)(')$/ims"))),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\''))
        )
    );
    $REC->Init($HTML['building'],'building');
    echo json_encode($HTML);


a third way to write the previous code:

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources = array('building'=>array(
        'in'=>array('type'=>'file','path'=>'storia_demo.html','depth'=>2,
            'regexp'=>array(
                array('pattern'=>"/var eventi = \{(.*)\};[$\r\n]/imsU"),
                array('key'=>true,'pattern'=>"/.*['\"](.*)['\"]:\[(.*)\](?:,|$)/imsU"),
                array('pattern'=>"/'(.*)'(?:,|$)/imsU"))),
        'out'=>array('type'=>'file','path'=>'storia_demo.html','target'=>'values',
            'regexp'=>array(
                array('pattern'=>"/(.*var eventi = \{)(.*)(\}.*center>)/imsU"),
                array('key'=>true,'sep'=>',',
                      'pattern'=>"/(.*['\"])(.*)(['\"]:\[)(.*)(\])(?:,|$)/imsU"),
                array('sep'=>',','pattern'=>"/(')(.*)(')$/ims"))),
        )
    );

    $HTML = array(
        'building'=>array(
            array('type'=>'select','name'=>'storia','label'=>'incontri di storia',
                'encode'=>false,'label'=>'','display'=>'0',
                'attrs'=>array('size'=>4,'style'=>'width: 100%; height: 100%; overflow: scroll'),
                'in'=>array('depth'=>2),
                'out'=>array('target'=>'values'),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\''))
        )
    );
    $REC->Init($HTML['building'],'building');
    echo json_encode($HTML);



simplified example from 'percor':
--------------------------------

<?php
    require_once('class.reconfig.php');
    $HTML = array(
        'building'=>array(
            array('type'=>'html','code'=>'<fieldset><legend align="left"><span class="row reconfig">periodici correnti</span></legend><ul><li>'),
            array('type'=>'select','name'=>'percor','encode'=>true,
                'label'=>'','display'=>'0',
                'in'=>array('type'=>'sql','group'=>'percor',
                    'query'=>'select text from fake_table where pid = 40','column'=>'text',
                    'dbconn'=>null,'dbhost'=>'localhost','dbname'=>'fake_db',
                    'dbuser'=>'root','dbpass'=>'',
                    'regexp'=>array(
                        array('pattern'=>
                            "/<ul id=[\"']percorUlList[\"']>(.*)<\/ul>(?:[[:space:]]|$)/ims"),
                        array('key'=>true,'pattern'=>
                            "/<!-- <a name=[\"'](.)[\"']> -->(.*)<!-- end -->/imsU"))),
                'out'=>array('type'=>'sql','group'=>'percor','target'=>'values','column'=>'text',
                    'query'=>'update fake_table set __SET__ where pid = 40',
                    'dbconn'=>null,'dbhost'=>'localhost','dbname'=>'fake_db',
                    'dbuser'=>'root','dbpass'=>'',
                    'regexp'=>array(
                        array('pattern'=>"/(.*<ul id=[\"']percorUlList[\"']>)(.*)(<\/ul>.*)/ims"),
                        array('key'=>true,'sep'=>'',
                            'pattern'=>
                                "/(<!-- <a name=[\"'])(.)([\"']> -->)(.*)(<!-- end -->)/imsU"))),
                'attrs'=>array('multiple'=>'multiple','size'=>4),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\'')),
            array('type'=>'html','code'=>'</li><li>'),
            ...
    ));
    ...
    $REC = new REConfig();
    $REC->auth_type='httpHeader'; //'none'; //'sql';
    $REC->auth_passwd=array('demo'=>'demo');
    $REC->auth_host = @$_POST['auth_host'];
    $REC->auth_user = @$_POST['auth_user'];
    $REC->auth_pass = @$_POST['auth_pass'];
    $REC->action = $_POST['action'];
    $REC->Init($HTML['building'],'building',true);
    echo json_encode($HTML);
?>

different way to write the previous code:

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources=array(
        'building'=>array(
            'in'=>array('type'=>'sql',
                'query'=>'select text from fake_table where pid = 40','column'=>'text',
                'dbconn'=>null,'dbhost'=>'localhost','dbname'=>'fake_db',
                'dbuser'=>'root','dbpass'=>'',
                'regexp'=>array(
                    array('pattern'=>
                        "/<ul id=[\"']percorUlList[\"']>(.*)<\/ul>(?:[[:space:]]|$)/ims"))),
            'out'=>array('type'=>'sql','target'=>'values','column'=>'text',
                'query'=>'update fake_table set __SET__ where pid = 40',
                'dbconn'=>null,'dbhost'=>'localhost','dbname'=>'fake_db',
                'dbuser'=>'root','dbpass'=>'',
                'regexp'=>array(
                    array('pattern'=>"/(.*<ul id=[\"']percorUlList[\"']>)(.*)(<\/ul>.*)/ims")))
        )
    );

    $HTML = array(
        'building'=>array(
            array('type'=>'html','code'=>'<fieldset><legend align="left"><span class="row reconfig">periodici correnti</span></legend><ul><li>'),
            array('type'=>'select','name'=>'percor','encode'=>true,
                'label'=>'','display'=>'0',
                'in'=>array('depth'=>1,
                    'regexp'=>array(
                        array('key'=>'1','pattern'=>
                            "/<!-- <a name=[\"'](.)[\"']> -->(.*)<!-- end -->/imsU"))),
                'out'=>array('target'=>'values',
                    'regexp'=>array(
                        array('key'=>true,'sep'=>'',
                            'pattern'=>
                                "/(<!-- <a name=[\"'])(.)([\"']> -->)(.*)(<!-- end -->)/imsU"))),
                'attrs'=>array('multiple'=>'multiple','size'=>4),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\'')),
            array('type'=>'html','code'=>'</li><li>'),
    ...
    );
    ...
    $REC->Init($HTML['building'],'building',true);
    echo json_encode($HTML);
?>


a third way to write the previous code:

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources=array(
        'building'=>array(
            'in'=>array('type'=>'sql','column'=>'text','rstype'=>'assoc','depth'=>1,
                'query'=>'select text from fake_table where pid = 40','column'=>'text',
                'dbconn'=>null,'dbhost'=>'localhost','dbname'=>'fake_db',
                'dbuser'=>'root','dbpass'=>'',
                'regexp'=>array(
                    array('pattern'=>
                        "/<ul id=[\"']percorUlList[\"']>(.*)<\/ul>(?:[[:space:]]|$)/ims"),
                        array('key'=>'1','pattern'=>
                            "/<!-- <a name=[\"'](.)[\"']> -->(.*)<!-- end -->/imsU"))),
            'out'=>array('type'=>'sql','target'=>'values','column'=>'text','rstype'=>'assoc',
                'query'=>'update fake_table set __SET__ where pid = 40',
                'dbconn'=>null,'dbhost'=>'localhost','dbname'=>'fake_db',
                'dbuser'=>'root','dbpass'=>'',
                'regexp'=>array(
                    array('pattern'=>"/(.*<ul id=[\"']percorUlList[\"']>)(.*)(<\/ul>.*)/ims"),
                        array('key'=>true,'sep'=>'',
                            'pattern'=>
                                "/(<!-- <a name=[\"'])(.)([\"']> -->)(.*)(<!-- end -->)/imsU")))
        )
    );

    $HTML = array(
        'building'=>array(
            array('type'=>'html','code'=>'<fieldset><legend align="left"><span class="row reconfig">periodici correnti</span></legend><ul><li>'),
            array('type'=>'select','name'=>'percor','encode'=>true,
                'label'=>'','display'=>'0',
                'in'=>array('column'=>'text','depth'=>1),
                'out'=>array('target'=>'values','column'=>'text'),
                'attrs'=>array('multiple'=>'multiple','size'=>4),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\'')),
            array('type'=>'html','code'=>'</li><li>'),
    ...
    );
    ...
    $REC->Init($HTML['building'],'building',true);
    echo json_encode($HTML);
?>

example from 'percor' demo version, extracting data from a text file (percor_demo.html)
-----------------------------------------------------------------------------------------

<?php
    require_once('class.reconfig.php');
    $HTML = array(
        'building'=>array(
            array('type'=>'html','code'=>'<fieldset><legend align="left"><span class="row reconfig">periodici correnti</span></legend><ul><li>'),
            array('type'=>'select','name'=>'percor','encode'=>true,
                'label'=>'','display'=>'0',
                'in'=>array('type'=>'file','path'=>'percor_demo.html',
                    'regexp'=>array(
                        array('pattern'=>
                            "/<ul id=[\"']percorUlList[\"']>(.*)<\/ul>(?:[[:space:]]|$)/ims"),
                        array('key'=>true,'pattern'=>
                            "/<!-- <a name=[\"'](.)[\"']> -->(.*)<!-- end -->/imsU"))),
                'out'=>array('type'=>'file','target'=>'values','path'=>'percor_demo.html',
                    'regexp'=>array(
                        array('pattern'=>"/(.*<ul id=[\"']percorUlList[\"']>)(.*)(<\/ul>.*)/ims"),
                        array('key'=>true,'sep'=>'',
                            'pattern'=>
                                "/(<!-- <a name=[\"'])(.)([\"']> -->)(.*)(<!-- end -->)/imsU"))),
                'attrs'=>array('multiple'=>'multiple','size'=>4),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\'')),
            array('type'=>'html','code'=>'</li><li>'),
    ...
    );
    ...
    $REC->Init($HTML['building'],'building',true);
    echo json_encode($HTML);
?>

different way to write the previous code:

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources=array(
        'building'=>array(
            'in'=>array('type'=>'file','path'=>'percor_demo.html',
                'regexp'=>array(
                    array('pattern'=>
                        "/<ul id=[\"']percorUlList[\"']>(.*)<\/ul>(?:[[:space:]]|$)/ims"))),
            'out'=>array('type'=>'file','target'=>'values','path'=>'percor_demo.html',
                'regexp'=>array(
                    array('pattern'=>"/(.*<ul id=[\"']percorUlList[\"']>)(.*)(<\/ul>.*)/ims")))
        )
    );

    $HTML = array(
        'building'=>array(
            array('type'=>'html','code'=>'<fieldset><legend align="left"><span class="row reconfig">periodici correnti</span></legend><ul><li>'),
            array('type'=>'select','name'=>'percor','encode'=>true,
                'label'=>'','display'=>'0',
                'in'=>array('depth'=>1,
                    'regexp'=>array(
                        array('key'=>true,'pattern'=>
                            "/<!-- <a name=[\"'](.)[\"']> -->(.*)<!-- end -->/imsU"))),
                'out'=>array('target'=>'values',
                    'regexp'=>array(
                        array('key'=>true,'sep'=>'','pattern'=>
                                "/(<!-- <a name=[\"'])(.)([\"']> -->)(.*)(<!-- end -->)/imsU"))),
                'attrs'=>array('multiple'=>'multiple','size'=>4),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\'')),
            array('type'=>'html','code'=>'</li><li>'),
    ...
    );
    ...
    $REC->Init($HTML['building'],'building',true);
    echo json_encode($HTML);
?>


a third way to write the previous code:

<?php
    require_once('class.reconfig.php');
    $REC = new REConfig();
    $REC->sources=array(
        'building'=>array(
            'in'=>array('type'=>'file','path'=>'percor_demo.html','depth'=>1,
                'regexp'=>array(
                    array('pattern'=>
                        "/<ul id=[\"']percorUlList[\"']>(.*)<\/ul>(?:[[:space:]]|$)/ims"),
                    array('key'=>true,'pattern'=>
                        "/<!-- <a name=[\"'](.)[\"']> -->(.*)<!-- end -->/imsU"))),
            'out'=>array('type'=>'file','target'=>'values','path'=>'percor_demo.html',
                'regexp'=>array(
                    array('pattern'=>"/(.*<ul id=[\"']percorUlList[\"']>)(.*)(<\/ul>.*)/ims"),
                    array('key'=>true,'sep'=>'',
                        'pattern'=>"/(<!-- <a name=[\"'])(.)([\"']> -->)(.*)(<!-- end -->)/imsU")))
        )
    );

    $HTML = array(
        'building'=>array(
            array('type'=>'html','code'=>'<fieldset><legend align="left"><span class="row reconfig">periodici correnti</span></legend><ul><li>'),
            array('type'=>'select','name'=>'percor','encode'=>true,
                'label'=>'','display'=>'0',
                'in'=>array('depth'=>1),
                'out'=>array('target'=>'values'),
                'attrs'=>array('multiple'=>'multiple','size'=>4),
                'event'=>array('onchange'=>'\'$reconfig.set_event(event);\'')),
            array('type'=>'html','code'=>'</li><li>'),
    ...
    );
    ...
    $REC->Init($HTML['building'],'building',true);
    echo json_encode($HTML);


example from 'bsmc', managing varius log file
---------------------------------------------

<?php
    require_once('class.reconfig.php');
    $HTML = array(
        'building'=>array(
            array('type'=>'textarea','name'=>'logstoria',
                'in'=>array('type'=>'file','path'=>'/tmp/storia.log','group'=>'storia'),
                'out'=>array('type'=>'file','path'=>'/tmp/storia.log','group'=>'storia')),
            array('type'=>'textarea','name'=>'logpercor',
                'in'=>array('type'=>'file','path'=>'/tmp/percor.log','group'=>'percor'),
                'out'=>array('type'=>'file','path'=>'/tmp/percor.log','group'=>'percor')),
            array('type'=>'textarea','name'=>'logavvisi',
                'in'=>array('type'=>'file','path'=>'/tmp/avvisi.log','group'=>'avvisi'),
                'out'=>array('type'=>'file','path'=>'/tmp/avvisi.log','group'=>'avvisi')),
            array('type'=>'textarea','name'=>'log900',
                'in'=>array('type'=>'file','path'=>'/tmp/900.log','group'=>'900'),
                'out'=>array('type'=>'file','path'=>'/tmp/900.log','group'=>'900')),
            array('type'=>'textarea','name'=>'logml',
                'in'=>array('type'=>'file','path'=>'/tmp/pop3ml.log','group'=>'ml'),
                'out'=>array('type'=>'file','path'=>'/tmp/pop3ml.log','group'=>'ml')),
            array('type'=>'textarea','name'=>'logusers',
                'in'=>array('type'=>'file','path'=>'/tmp/users.log','group'=>'users'),
                'out'=>array('type'=>'file','path'=>'/tmp/users.log','group'=>'users')),
        )
    );
    $REC->Init($HTML['building'],'building',true);
    echo json_encode($HTML);



simplified example from 'bibris' (controller.php):
-------------------------------------------------

    $REC = new REConfig();
    ...
    $REC->sources = array('building'=>array(
            'in'=>array('type'=>'sql','column'=>true,
                'query'=>'SELECT * FROM table WHERE key = 1',
                'driver'=>'mysqli','dbconn'=>null,'dbhost'=>'localhost',
                'dbname'=>'testdb','dbuser'=>'dbuser','dbpass'=>'letmein'
                )));
    ...

    $HTML = array(
        'building'=>array(
            array('type'=>'input','name'=>'sqlsearch','encode'=>true,
                'in'=>false,
                'event'=>array('onfocus'=>'\'$reconfig.search_got_focus(this);\''),
                'value'=>'search in: manoscritti',
                'html'=>array('prepend'=>
                    '<form action=\'javascript:$reconfig.run_search(null,"search.php");\'>',
                              'append'=>
                    '<a href..........
                )
            ),
            ....
        )
    );
    ...



example from 'bibris' of multiple output (detail.php):
---------------------------------------------------------

$REC = new REConfig();
...
$REC->sources = array(
    'dvPopupTxt'=>array(
        'in'=>array('type'=>'sql',
            'query'=>$REC->BuildQuery('_immagini'),
            'driver'=>__DRIVER__,'dbconn'=>null,'dbhost'=>__HOST__,
            'dbname'=>__DBNAME__,'dbuser'=>__USER__,'dbpass'=>__PASS__),
        'out'=>array('type'=>'sql',
            'query'=>'UPDATE _immagini SET __SET__ WHERE id='))
    'collocazione'=array('name'=>'collocazione',
        'out'=>array('type'=>'sql',
            'driver'=>__DRIVER__,'dbconn'=>null,'dbhost'=>__HOST__,
            'dbname'=>__DBNAME__,'dbuser'=>__USER__,'dbpass'=>__PASS__,
            'query'=>"UPDATE _immagini SET __SET__ WHERE tipologia='".
                @$sqlkeys[$_selected_menu][$_selected_item]."' and titolo="),
        'data'=>array('collocazione'=>'')
    )
);

$HTML = array(
    'dvPopupTxt'=>array(
        array('type'=>'input','name'=>'bid','label'=>'codice SBN',
            'in'=>array('column'=>'bid'),'out'=>true
        ),
        ...
        // item with 2 output group 'dvPopupTxt' and 'extend'
        array('type'=>'input','name'=>'sottotitolo','label'=>'sottotitolo','encode'=>true,
            'in'=>array('column'=>'soggetto'),
            'out'=>array(
                array('group'=>'extend','type'=>'file','path'=>$xmlpath,'depth'=>1,'regexp'=>array(
                    array('pattern'=>'/(.*<Param name="sottotitolo" value=")(.*)(".*item>)$/imsU'))),
                array('group'=>'dvPopupTxt','column'=>'soggetto')
            )
        ),
        ...
        // item with 3 output group 'dvPopupTxt', 'extend' and 'collocazione'
        array('type'=>'input','name'=>'collocazione','label'=>'collocazione','encode'=>true,
            'in'=>array('group'=>'extend',
                'regexp'=>array(
                    array('pattern'=>'/<Param name="collocazione" value="(.*)"/imsU'))),
            'out'=>array(
                array('group'=>'extend','regexp'=>array(
                    array('pattern'=>'/(.*<Param name="collocazione" value=")(.*)(".*item>)$/imsU'))),
                array('group'=>'dvPopupTxt','column'=>'collocazione'),
                array('group'=>'collocazione','column'=>'collocazione')
            )
        ),
        ...






OPTIONS LIST:

[encode]
    values will be encoded/decoded with rawurlencode (php) / unescape (javascript) for input and
    escape (javascript) / rawurlencode (php) for output
[name]
    the name of the html element
[label]
    the label of the html element
[type]
    the html element type: 
        predefined: function, eval, radio, checkbox, select, img, button, textarea, input, none
        others (div, a,..) for example: 
            array('type'=>'a','name'=>'fascicolo','encode'=>true,
                'html'=>array('prepend'=>'<li>','append'=>'</li>'),
                .....
        with 'none' the element is not displayed automatically, use javascript code.

[depth] define the depth of regexp result values for input and output. it can be overridden by
    [in][depth] and [out][depth].
    0 => 'string',  1 => monodimensional array, 2 => bidimensional array
[in] array / false (no input data)
    [type] sql/file
    [rstype] num / assoc / both
             (SQL only) retrieve sql data from _fetch_array as numeric array, associative array or
             both, so you can set 'column' with a numeric index or field name. Pay attention with
             this option you have output need, 'out''column' must be a string (field name)
    [group] with this field you can associate the item with another group
    [driver] [dbhost] [dbname] [dbuser] [dbpass] db connection data
        [query] the input query
        [column] 
            'not set' -> the corresponding group result data (REConfig::sources[group]['data'] for
                         example REConfig::sources['building']['data']) will be set as sql_fetch_array
                         for one record
                         'field1'=>'value'
                         'field2'=>'value'
                         for more than one record will be set like 'true'
            'true'    -> (SQL only) 
                         sources[group]['data'] will be an array (even for just one record):
                         'field1'=>array('value1','value2',....)
                         'field2'=>array('value1','value2',....)
                         ....
            'somefield' -> sources[group]['data'] will be an array:
                         'somefield'=>'value'
                         the (target) value will be the set with the corresponding item
            "array('field1'=>'field2')"  or  "array('field1'=>array('field2','field2'))"
                         retrieve 2 or more fields value as associative array (for SQL use 
                         'rstype' with 'assoc' or 'both' value)
            number    -> retrieve the 'number' element of array result (for SQL use 'rstype' with
                         'num' or 'both' value)
    [func] you can put php code that will be `eval`d after file/sql input and before 'regexp'd.
    [path] if type = 'file' this is the input file pathname (ie. '/some/dir/file.txt' or
           'http://site.com/file')
    [regexp] single or multiple array
        [key] if set to 'true' the first field captured will be the index of array result
        [func] default function for regexp id 'preg_match_all', setting this option with 'split'
               will be used 'preg_split' for this regexp
        [pattern] the regexp/split pattern
                  with 'key' unset insert 1 capturing parenthesis, with 'key' set to 'number' insert 
                  2 capturing parenthesis, where first captured value sets array key, second
                  its value
    [depth] the result input array depth. if there is regexp option normally is unnecessary, or
            set it to regexp array sizeof
    [target] by default the input data result is [values].
             with this option you can set another field
    [encode] input values will be encoded
    [utf8_decode] apply php 'utf8_decode' function to input values
    [lowercase] set to 'true' input values will be set to lowercase
    [uppercase] set to 'true' input values will be set to uppercase

[out] -> could be single or multiple arrays for multiple sql/file output / false (no output setup)
    [type] sql/file
    [group] with this field you can associate the item with another group
    [driver] [dbhost] [dbname] [dbuser] [dbpass] db connection data
        [query] the setup query
        [column] like [in][column] exept for 'number' value for SQL output, it must be alfanum value
    [func] you can put php code that will be `eval`d before file/sql output and before 'regexp'd
    [path] if type = 'file' this is the output file pathname (ie. '/some/dir/file.txt')
           'http://site.com/file')
    [regexp] single or multiple array. the array will be applied to output data in reverse mode
        [key] if set to 'true' the first field captured will be the index of array result
        [sep] the data separator rebuilding output value (ie. ',')
        [pattern] the regexp pattern.
                  with 'key' unset insert 3 capturing parenthesis, first from data begin to first
                  field captured, third from field captured to data end.
                  with 'key' set to number insert 5 capturing parenthesis, first from data begin
                  to first field captured, third from from first field captured to second field
                  captured, fifth from this to data end.
                  (be very very careful with 'U' (unaggressive) flag with out regexp)
    [depth] normally calculated automatically. Used for set saving array the same depth of output
            regexp sizeof
    [target] by default the output data for writing is [value] with data.
             with this option you can set another field (ie. [values])
[values]    normally used for input. for example could be an array of values to fill a 'select'
            element.
[value]     normally used for output. it can be string or array (for example 'select' multiple)
[display]   used with 'select' html elements. set to '0' display result value index as option,
            set to '1' display result values elements as options.
[selbycode] used with 'radio','checkbox' and 'select' html elements.
            if 'true' set 'selected' option with index,
            if 'null'/'false' set 'selected' option with value
[lowercase] not set do nothing
            set to 'false' check value in lowercase mode (index and description), leaving result
            values untouched.
            set to 'true' check value in lowercase mode (index and description), changing result
            values to lowercase.
[uppercase] not set do nothing
            set to 'false' check value in uppercase mode (index and description), leaving result
            values untouched.
            set to 'true' check value in uppercase mode (index and description), changing result
            values to uppercase.
[code]      html/javascript code used with 'html' type, javascript only for 'function'/'eval' type
[parms]     parameters passed to 'function' code

RUNNING OPTIONS

[action]    'login' build authentication form for user/password request and run 'exec' if success.
                    authentication can be 
            'exec'  POST 'controller' php script
            'build' build html elements
            'fill'  set html element values 
            'get_data' retrieve all html elements value, normally before 'save'
            'save'  POST 'controller' php script running setup code for output data
[items]     choose which configuration group process. if unset will be set by jquery plugin query
[controller] php script to be excecuted
[auth_driver] [auth_host] [auth_user] [auth_pass]
            for authentication
[json_data] object containing data for 'save' action
[do_before_login] [do_before_exec] [do_after_exec] [do_before_build] [do_after_build]
[do_before_save]  [do_after-save]
            javascript code excecuted at that specific point
[lang]      language code: 'en' 'it' ...
[language]  language object, for example:
                language={'it':{'display':'visualizza','update':'aggiorna',..}};
[all_data]  used for saving data. if not set will be sent to 'setup' only changed values, if 'true'
            there is not change control








  Files folder image Files  
File Role Description
Files folder imagecss (2 files)
Files folder imagejs (3 files)
Accessible without login HTML file build.html Aux. build reconfig elements
Accessible without login Plain text file build.php Aux. build.php
Plain text file class.reconfig.php Class class script source
Plain text file class.sql.php Class manage sql data
Accessible without login Plain text file README Doc. documentation file
Accessible without login Plain text file validate.php Aux. user authentication script

  Files folder image Files  /  css  
File Role Description
  Accessible without login HTML file build.css Aux. build css style
  Accessible without login Plain text file reconfig.css Data class script source

  Files folder image Files  /  js  
File Role Description
  Accessible without login HTML file build.js Aux. javascript code for build
  Accessible without login Plain text file jquery.reconfig-1.0.js Data jquery plugin
  Accessible without login Plain text file json2.js Data json javascript library

 Version Control Unique User Downloads Download Rankings  
 0%Total:426All time:5,871
 This week:1This week:1,053Up
 User Comments (1)