Example #1
0
function const_sql($modules_name, $tables_module_table, $tables_name, $tables_champs)
{
    global $xoopsDB;
    $sql_file = "mysql.sql";
    $sql_path_file = XOOPS_ROOT_PATH . "/modules/TDMCreate/modules/" . $modules_name . "/sql/" . $sql_file;
    $text = const_champs($modules_name, $tables_module_table, $tables_name, $tables_champs, '', 0, 0, 0, 2);
    //Integration du contenu dans le fichier mysql.sql
    $handle = fopen($sql_path_file, "a+");
    if (is_writable($sql_path_file)) {
        if (fwrite($handle, $text) === FALSE) {
            echo '<tr>
					<td>' . _AM_TDMCREATE_CONST_NOTOK_SQL . '<br>' . $blocs_path_file . '</td>
					<td><img src="./../images/deco/off.gif"></td>
			  </tr>';
            exit;
        }
        echo '<tr>
				<td>' . _AM_TDMCREATE_CONST_OK_SQL . '</td>
				<td><img src="./../images/deco/on.gif"></td>
			  </tr>';
        fclose($handle);
    } else {
        echo '<tr>
					<td>' . _AM_TDMCREATE_CONST_NOTOK_SQL . '<br>' . $sql_path_file . '</td>
					<td><img src="./../images/deco/off.gif"></td>
			  </tr>';
    }
}
Example #2
0
function const_blocs($modules, $modules_name, $tables_module_table, $tables_name, $tables_champs, $tables_parametres, $topic)
{
    $language = '_MB_' . strtoupper($tables_module_table) . '';
    $modules_name_minuscule = strtolower($modules_name);
    $blocs_file = "blocks_" . $tables_name . ".php";
    $blocs_path_file = XOOPS_ROOT_PATH . "/modules/TDMCreate/modules/" . $modules_name . "/blocks/" . $blocs_file;
    $constructor = const_champs($modules_name, $tables_module_table, $tables_name, $tables_champs, $tables_name, 0, 0, 0);
    $en_tete = const_entete($modules, 0);
    $text = '<?php' . $en_tete . '	
include_once XOOPS_ROOT_PATH."/modules/' . $modules_name . '/include/functions.php";
	
function b_' . $modules_name_minuscule . '_' . $tables_name . '($options) {
include_once XOOPS_ROOT_PATH."/modules/' . $modules_name . '/class/' . $tables_name . '.php";
$myts =& MyTextSanitizer::getInstance();

$' . $tables_name . ' = array();
$type_block = $options[0];
$nb_' . $tables_name . ' = $options[1];
$lenght_title = $options[2];

$' . $tables_name . 'Handler =& xoops_getModuleHandler("' . $tables_module_table . '", "' . $modules_name . '");
$criteria = new CriteriaCompo();
array_shift($options);
array_shift($options);
array_shift($options);
';
    if ($topic == 1) {
        $text .= 'if (!(count($options) == 1 && $options[0] == 0)) {
$criteria->add(new Criteria("' . $tables_name . '_topic", block_addCatSelect($options),"IN"));
}
';
    }
    $text .= '
switch ($type_block) 
{
	// pour le bloc: ' . $tables_name . ' recents
	case "recent":
		$criteria->add(new Criteria("' . $tables_name . '_online", 1));
		$criteria->setSort("' . $tables_name . '_date_created");
		$criteria->setOrder("DESC");
	break;
	// pour le bloc: ' . $tables_name . ' du jour
	case "day":	
		$criteria->add(new Criteria("' . $tables_name . '_online", 1));
		$criteria->add(new Criteria("' . $tables_name . '_date_created", strtotime(date("Y/m/d")), ">="));
		$criteria->add(new Criteria("' . $tables_name . '_date_created", strtotime(date("Y/m/d"))+86400, "<="));
		$criteria->setSort("' . $tables_name . '_date_created");
		$criteria->setOrder("ASC");
	break;
	// pour le bloc: ' . $tables_name . ' aléatoires
	case "random":
		$criteria->add(new Criteria("' . $tables_name . '_online", 1));
		$criteria->setSort("RAND()");
	break;
}


$criteria->setLimit($nb_' . $tables_name . ');
$' . $tables_name . '_arr = $' . $tables_name . 'Handler->getall($criteria);';
    $text .= '
	foreach (array_keys($' . $tables_name . '_arr) as $i) 
	{
	';
    $prefix = '$' . $tables_name . '_arr[$i]->getVar';
    //Champs
    $champs = explode("|", $tables_champs);
    $nb_champs = count($champs);
    //Parametres
    $parametres = explode("|", $tables_parametres);
    $nb_parametres = count($parametres);
    $j = 0;
    $structure_parametres[3] = 0;
    for ($i = 0; $i < $nb_champs; $i++) {
        $structure_champs = explode(":", $champs[$i]);
        if ($i != 0) {
            $structure_parametres = explode(":", $parametres[$j]);
            $j++;
        }
        if ($structure_parametres[3] == 1 || $i == 0) {
            $text .= '	$' . $tables_name . '[$i]["' . $structure_champs[0] . '"] = ' . $prefix . '("' . $structure_champs[0] . '");
		';
        }
    }
    $text .= '
	}
return $' . $tables_name . ';
}

function b_' . $modules_name_minuscule . '_' . $tables_name . '_edit($options) {';
    if ($topic == 1) {
        $text .= '
	include_once XOOPS_ROOT_PATH."/modules/' . $modules_name . '/class/topic.php";
	
	$topicHandler =& xoops_getModuleHandler("' . $modules_name . '_topic", "' . $modules_name . '");
	$criteria = new CriteriaCompo();
	$criteria->setSort("topic_title");
	$criteria->setOrder("ASC");
	$topic_arr = $topicHandler->getall($criteria);
	';
    }
    $text .= '
	$form = "".' . $language . '_DISPLAY."\\n";
	$form .= "<input type=\\"hidden\\" name=\\"options[0]\\" value=\\"".$options[0]."\\" />";
	$form .= "<input name=\\"options[1]\\" size=\\"5\\" maxlength=\\"255\\" value=\\"".$options[1]."\\" type=\\"text\\" />&nbsp;<br />";
	$form .= "".' . $language . '_TITLELENGTH." : <input name=\\"options[2]\\" size=\\"5\\" maxlength=\\"255\\" value=\\"".$options[2]."\\" type=\\"text\\" /><br /><br />";
	array_shift($options);
	array_shift($options);
	array_shift($options);';
    $text .= '
	$form .= "".' . $language . '_CATTODISPLAY."<br /><select name=\\"options[]\\" multiple=\\"multiple\\" size=\\"5\\">";
	$form .= "<option value=\\"0\\" " . (array_search(0, $options) === false ? "" : "selected=\\"selected\\"") . ">" .' . $language . '_ALLCAT . "</option>";
	foreach (array_keys($topic_arr) as $i) {
		$form .= "<option value=\\"" . $topic_arr[$i]->getVar("topic_id") . "\\" " . (array_search($topic_arr[$i]->getVar("topic_id"), $options) === false ? "" : "selected=\\"selected\\"") . ">".$topic_arr[$i]->getVar("topic_title")."</option>";
	}
	$form .= "</select>";

	return $form;
}
	
?>';
    //Integration du contenu dans le bloc
    $handle = fopen($blocs_path_file, "w");
    if (is_writable($blocs_path_file)) {
        if (fwrite($handle, $text) === FALSE) {
            echo '<tr>
					<td>' . _AM_TDMCREATE_CONST_NOTOK_BLOCS . '<br>' . $blocs_path_file . '</td>
					<td><img src="./../images/deco/off.gif"></td>
				  </tr>';
            exit;
        }
        echo '<tr>
				<td>' . _AM_TDMCREATE_CONST_OK_BLOCS . '</td>
				<td><img src="./../images/deco/on.gif"></td>
			  </tr>';
        fclose($handle);
    } else {
        echo '<tr>
				<td>' . _AM_TDMCREATE_CONST_NOTOK_BLOCS . '<br>' . $blocs_path_file . '</td>
				<td><img src="./../images/deco/off.gif"></td>
			  </tr>';
    }
}
Example #3
0
function const_class($modules, $modules_name, $tables_module_table, $tables_name, $tables_champs, $tables_parametres)
{
    $language = '_AM_' . strtoupper($modules_name) . '_';
    $modules_name_minuscule = strtolower($modules_name);
    $class_name = $tables_name;
    $class_file = $class_name . ".php";
    $class_path_file = XOOPS_ROOT_PATH . "/modules/TDMCreate/modules/" . $modules_name . "/class/" . $class_file;
    $constructor = const_champs($modules_name, $tables_module_table, $tables_name, $tables_champs, $language, 0, 0, 0, 0);
    $en_tete = const_entete($modules, 0);
    //Champs
    $champs_total = explode("|", $tables_champs);
    $nb_champs = count($champs_total);
    //print_r($champs_total);
    //Parametres
    $parametres_total = explode("|", $tables_parametres);
    //Recuperation des parametres affichage dans le formulaire
    for ($i = 0; $i < $nb_champs; $i++) {
        $champs = explode(":", $champs_total[$i]);
        //Afficher dans les elements du formulaire et choisir le type
        if ($i == 0) {
            $champs_param_elements[$i] = '0';
            $champs_param_display_form[$i] = '0';
        } else {
            $parametres1 = explode(":", $parametres_total[$i - 1]);
            //print_r($parametres1);
            $champs_param_display_form[$i] = $parametres1[3];
            $champs_param_elements[$i] = $parametres1[0];
            $champs_param_required_field[$i] = $parametres1[6];
            if ($parametres1[4] == 1) {
                $champs_param_main_field = $champs[0];
            }
        }
    }
    $form = const_champs($modules_name, $tables_module_table, $tables_name, $tables_champs, $language, $champs_param_display_form, $champs_param_elements, $champs_param_required_field, 1);
    $text = '<?php' . $en_tete . '
	
	if (!defined("XOOPS_ROOT_PATH")) {
		die("XOOPS root path not defined");
	}

	if (!class_exists("XoopsPersistableObjectHandler")) {
		include_once XOOPS_ROOT_PATH."/modules/' . $modules_name . '/class/object.php";
	}

	class ' . $tables_module_table . ' extends XoopsObject
	{ 
		//Constructor
		function __construct()
		{
			$this->XoopsObject();';
    $text .= '
			' . $constructor . '
			// Pour autoriser le html
			$this->initVar("dohtml", XOBJ_DTYPE_INT, 1, false);
		';
    $text .= '	
		}

		function ' . $tables_module_table . '()
		{
			$this->__construct();
		}
	
		function getForm($action = false)
		{
			global $xoopsDB, $xoopsModuleConfig;
		
			if ($action === false) {
				$action = $_SERVER["REQUEST_URI"];
			}
		
			$title = $this->isNew() ? sprintf(' . $language . strtoupper($tables_name) . '_ADD) : sprintf(' . $language . strtoupper($tables_name) . '_EDIT);

			include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php");

			$form = new XoopsThemeForm($title, "form", $action, "post", true);
			$form->setExtra(\'enctype="multipart/form-data"\');
			
			';
    $text .= '' . $form . '';
    $text .= '
			$form->addElement(new XoopsFormHidden("op", "save_' . $tables_name . '"));
			$form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
			$form->display();
			return $form;
		}
	}';
    $text .= '
	class ' . $modules_name . $tables_module_table . 'Handler extends XoopsPersistableObjectHandler 
	{

		function __construct(&$db) 
		{
			parent::__construct($db, "' . $tables_module_table . '", "' . $tables_module_table . '", "' . $tables_name . '_id", "' . $champs_param_main_field . '");
		}

	}
	
?>';
    //Integration du contenu dans la classe
    $handle = fopen($class_path_file, "w");
    if (is_writable($class_path_file)) {
        if (fwrite($handle, $text) === FALSE) {
            echo '<tr>
					<td>' . sprintf(_AM_TDMCREATE_CONST_NOTOK_CLASS, $tables_name) . '<br>' . $class_path_file . '</td>
					<td><img src="./../images/deco/off.gif"></td>
			  </tr>';
            exit;
        }
        echo '<tr>
				<td>' . sprintf(_AM_TDMCREATE_CONST_OK_CLASS, $tables_name) . '</td>
				<td><img src="./../images/deco/on.gif"></td>
			  </tr>';
        fclose($handle);
    } else {
        echo '<tr>
					<td>' . sprintf(_AM_TDMCREATE_CONST_NOTOK_CLASS, $tables_name) . '<br>' . $class_path_file . '</td>
					<td><img src="./../images/deco/off.gif"></td>
			  </tr>';
    }
}