Categories > TinyButStrong general (FR) >

MergeBlock de base pseudo récursif

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: zeflex
Date: 2011-08-23
Time: 15:13

MergeBlock de base pseudo récursif

Salut,

J'aimerai savoir comment attribuer chaque valeur des tableaux à chaque checkbox, sans préciser le type de block . A vrai dire je n'ai pas besoin de blocks dans mon cas.

Voici un bout du code essentiel :

En PHP :
$TBS->MergeBlock('name','array',array(
'general_informations','original_title','original_language','duration','amg','studio','image_url','genres','production_year','origin_country','cc','cavco_certified_number','cavco_points','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','',''
));
$TBS->MergeBlock('checkbox','array',array(
'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'
,'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'
,'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'
));

En HTML
    <form id="main_form" action="#" method="post" onsubmit="return false;" class="" style="float: left; width: 100%">
        <fieldset>
            <ul>
                <li><input type="checkbox" name="[name.val]" class="main_cb" id="cgi"/>[checkbox.val;att=selected;atttrue='Y'] General informations</li>
                <ul class="gi">
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Original title</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Original language</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Duration</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] AMG</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Studio</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Image url</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Genres</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Year of production</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Country of origin</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Canadian certified</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Cavco certified number</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Cavco points</li>
                </ul>
                <li><input type="checkbox" name="[name.val]" class="main_cb" id="cfo"/>[checkbox.val;att=selected;atttrue='Y'] Formats</li>
                <ul>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Format</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Language</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Dub title</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] # Title</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] UPC</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Pricing</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] SRP</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Minimum wholesale price</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Release date</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Closed captionning</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Closed captionning language</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Subtitles</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Subtitles language</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Video description</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Extra features</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Number of discs</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Link Type</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Link URL</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Materials received</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Audio</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Aspect ratio</li>
                    <li><input type="checkbox" name="[name.val]"/>[checkbox.val;att=selected;atttrue='Y'] Commentary</li>
                </ul>


J'ai pas mis tout le HTML qui est assez lourd, plus de 120 champs de mémoire.

J'ai donc besoin que name.val n°1 corresponde à la valeur du tableau n°0 et ainsi de suite, pareil pour checkbox.val ...

Je sèches pas mal. Merci .
By: Skrol29
Date: 2011-08-24
Time: 00:26

Re: MergeBlock de base pseudo récursif

Salut,
PHP :
$TBS->MergeField('name', array(
  'general_informations',
  'original_title',
  'original_language',
  ...
);

$TBS->MergeField('checkbox', array(
  'Y',
  'Y',
  'Y',
  ...
);

HTML :
     <li><input type="checkbox" name="[name.0]"/>[checkbox.0;att=selected;atttrue='Y'] Original title</li>
     <li><input type="checkbox" name="[name.1]"/>[checkbox.1;att=selected;atttrue='Y'] Original language</li>
     <li><input type="checkbox" name="[name.2]"/>[checkbox.2;att=selected;atttrue='Y'] Duration</li>
     ...
By: zeflex
Date: 2011-08-30
Time: 15:26

Re: MergeBlock de base pseudo récursif

Hello, thanks ca marche bien.

Maintenant je bloque sur la fonction qui permets de cocher les checkbox si elles sont dans un array. Voici mon code :

PHP :
function checkbox_report_tpl($BlockName, &$CurrRec, $RecNum) {
  $CurrRec[1] = in_array( $CurrRec[0] , $GLOBALS['checked_fields'] );
}

$report_tpl_id = '';
if ( !empty($_GET['select_report']) ) {
    $tpl_id = intval($_POST['report_select']);
    $sql = mysql_query("SELECT * FROM report_tpl WHERE user_id = $user_id AND tpl_id = $tpl_id");
    if ( mysql_num_rows($sql) ) {
        $checked_fields = array();
        $row = mysql_fetch_array($sql);
        $report_name = $row['tpl_name'];
        $db_fields = $row['tpl_fields'];
        $checked_fields = str_replace('|','',explode('||',$db_fields));
        // foreach( $checked_fields AS $key=>$val ) {
            // $report_fields_array[] = array("id"=>$key,"value"=>$val);
        // }
        // $report_fields_array = $checked_fields;
        // print_r($report_fields_array);
        $report_tpl_id = $tpl_id;
    }
}

HTML :
                    <li><input type="checkbox" name="[name.1;ondata=checkbox_report_tpl]"/>[checkbox.1;att=input#checked;atttrue=1] Original title</li>
                    <li><input type="checkbox" name="[name.2;ondata=checkbox_report_tpl]"/>[checkbox.2;att=input#checked;atttrue=1] Original language</li>
                    <li><input type="checkbox" name="[name.3;ondata=checkbox_report_tpl]"/>[checkbox.3;att=input#checked;atttrue=1] Duration</li>
                    <li><input type="checkbox" name="[name.4;ondata=checkbox_report_tpl]"/>[checkbox.4;att=input#checked;atttrue=1] AMG</li>

Comment cocher la case si le nom de l'input est présent dans l'array $checked_fields ?

Merci.
By: Skrol29
Date: 2011-08-31
Time: 23:43

Re: MergeBlock de base pseudo récursif

Bonjour,

La paramètre "ondata" ne fonctionne pas avec un MergeField().
Tu dois donc revoir les données de ton tableau avec le MergeField() de sorte qu'elles contiennent déjà l'information 'checked'.