initial commit
initial commit

file:b/.gitignore (new)
--- /dev/null
+++ b/.gitignore
@@ -1,1 +1,2 @@
+working
 

file:b/crud.php (new)
--- /dev/null
+++ b/crud.php
@@ -1,1 +1,52 @@
-
+<?php

+

+extract ($_POST);

+$module_basename = strtolower (str_replace (" ", "_", $module_name));

+

+if ( $_GET['do'] == "schema" ) {

+	if ( $module_name && $module_table ) {

+		ob_start ();

+		include ("tpl/crud.install.php");

+		$crud_install = ob_get_contents();

+		ob_end_clean();

+		preg_match_all ("|\_schema\(\)\{(.*)return|isU", $crud_install, $schema);

+	 	echo $schema[1][0];

+		exit ();

+	}

+} else {

+	ob_start ();

+	include ("tpl/crud.info.php");

+	$crud_info = ob_get_contents();

+	ob_end_clean();

+

+	ob_start ();

+	include ("tpl/crud.install.php");

+	$crud_install = ob_get_contents();

+	ob_end_clean();

+

+	ob_start ();

+	include ("tpl/crud.module.php");

+	$crud_module = ob_get_contents();

+	ob_end_clean();

+

+

+	$file = tempnam("tmp", "zip");

+	$zip = new ZipArchive();

+	$zip->open($file, ZipArchive::OVERWRITE);

+	$zip->addFromString($module_basename."/images/active.png", file_get_contents("tpl/images/active.png"));

+	$zip->addFromString($module_basename."/images/inactive.png", file_get_contents("tpl/images/inactive.png"));

+	$zip->addFromString($module_basename."/".$module_basename.".info", $crud_info);

+	$zip->addFromString($module_basename."/".$module_basename.".install", $crud_install);

+	$zip->addFromString($module_basename."/".$module_basename.".module", $crud_module);

+	$zip->close();

+

+	// Stream the file to the client

+	header("Content-Type: application/zip");

+	header("Content-Length: " . filesize($file));

+	header("Content-Disposition: attachment; filename=\"".$module_name.".zip\"");

+	readfile($file);

+

+	unlink($file);

+}

+

+?>

file:b/index.php (new)
--- /dev/null
+++ b/index.php
@@ -1,1 +1,131 @@
-
+<!DOCTYPE html

+     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

+<head>

+    <title>DRUPAL CRUD Module Creator</title>

+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

+    <script type="text/javascript" src="https://www.google.com/jsapi"></script>

+    <script type="text/javascript">

+        google.load("jquery", "1.7.1");

+        google.load("jqueryui", "1.8.16");

+    </script>

+

+    <link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/black-tie/jquery-ui.css" rel="stylesheet" media="all" />

+    <link type="text/css" href="http://speedtest.razvi.ro/css/colors-classic.css" rel="stylesheet" />

+    <link type="text/css" href="http://speedtest.razvi.ro/css/colors-fresh.css" rel="stylesheet" />

+    <link type="text/css" href="http://speedtest.razvi.ro/css/global.css" rel="stylesheet" />

+</head>

+<body class="wp-admin">

+

+<form action="crud.php" id="crud" method="post">

+

+<h3>Module</h3>

+

+<table>

+	<tr>

+		<td>Name</td>

+	</tr>

+	<tr>

+		<td><input type="text" size="50" name="module_name" id="module_name" /></td>

+	</tr>

+	<tr>

+		<td>Description</td>

+	</tr>

+	<tr>

+		<td><input type="text" size="50" name="module_description" /></td>

+	</tr>

+</table>

+

+<div class="step2" style="display: none;">

+<strong>Create the table schema</strong><br />

+<table>

+	<tr>

+		<td>Table name</td>

+	</tr>

+	<tr>

+		<td><input type="text" size="50" name="module_table" id="module_table" /></td>

+	</tr>

+</table>

+

+<div class="step3" style="display: none;">

+

+<div id="fields">

+<table>

+	<tr>

+		<td><strong>Table fields</strong></td>

+	</tr>

+	<tr>

+		<td>

+			1. <input type="text" size="50" name="field_name[1]" value="id" readonly="true" />

+   			<select name="field_type[1]">

+   				<option value="varchar">varchar</option>

+   				<option value="int" selected="selected">int</option>

+   				<option value="tinyint">tinyint</option>

+   				<option value="text">text</option>

+   				<option value="datetime">datetime</option>

+			</select> auto_increment

+		</td>

+	</tr>

+</table>

+</div>

+<table>

+	<tr>

+		<td>

+			<span id="status_number">2.</span> <input type="text" size="50" name="field_name[2]" id="status_field" value="status" readonly="true" />

+   			<select name="field_type[2]" id="status_type">

+   				<option value="varchar">varchar</option>

+   				<option value="int">int</option>

+   				<option value="tinyint" selected="selected">tinyint</option>

+   				<option value="text">text</option>

+   				<option value="datetime">datetime</option>

+			</select> status (1/0)

+		</td>

+	</tr>

+</table>

+<a href="#" id="addnewfield">Add new field</a>

+<br />

+<br />

+

+<input type="button" id="view_schema" name="view_schema" value="View schema" />

+<input type="submit" name="sub" value="Make module" />

+

+<pre id="schema"></pre>

+</div>

+</div>

+

+</form>

+

+<script type="text/javascript">

+	var field = 2;

+	$("#addnewfield").click(function (){

+		$("#fields").append ("<table><tr><td>"+field+". <input type=\"text\" size=\"50\" name=\"field_name["+field+"]\" /><select name=\"field_type["+field+"]\"><option value=\"varchar\">varchar</option><option value=\"int\">int</option><option value=\"tinyint\">tinyint</option><option value=\"text\">text</option><option value=\"datetime\">datetime</option></select></td></tr></table>");

+		field++;

+		$("#status_number").html(field+'.');

+		$("#status_field").attr("name", 'field_name['+field+']');

+		$("#status_type").attr("name", 'field_type['+field+']');

+	});

+	function refreshSchema (timeout) {

+		setTimeout(function(){

+			$.post ("crud.php?do=schema", $("#crud").serialize(), function (html){

+				$("#schema").html (html);

+				refreshSchema (3000);

+			});

+		},timeout);

+	}

+	//refreshSchema (0);

+	$("#view_schema").click (function (){

+		$.post ("crud.php?do=schema", $("#crud").serialize(), function (html){

+			$("#schema").html (html);

+		});

+	});

+	$("#module_name").keyup (function (){

+		$(".step2").slideDown(200);

+	});

+	$("#module_table").keyup (function (){

+		$(".step3").slideDown(200);

+	});

+</script>

+

+</body>

+</html>

file:b/tpl/crud.info.php (new)
--- /dev/null
+++ b/tpl/crud.info.php
@@ -1,1 +1,5 @@
-
+name = <?=$module_name."\r\n";?>
+description = <?=$module_description."\r\n";?>
+package = CRUD<?="\r\n";?>
+core = 7.x<?="\r\n";?>
+version = 7.x<?="\r\n";?>

--- /dev/null
+++ b/tpl/crud.install.php
@@ -1,1 +1,63 @@
-
+<?="<?php";?>

+

+/**

+* Implements hook_install().

+*/

+function <?=$module_basename;?>_install(){

+}

+

+/**

+* Implements hook_uninstall().

+*/

+function <?=$module_basename;?>_uninstall(){

+}

+

+/**

+* Implements hook_schema().

+*/

+function <?=$module_basename;?>_schema(){

+	$schema['<?=$module_table;?>'] = array(

+		'description' => '',

+		'fields' => array(

+			'id' => array(

+				'description' => '',

+				'type' => 'serial',

+				'not null' => TRUE,

+			),

+			<? unset ($field_name[1]); ?>

+			<?foreach ($field_name as $key => $field): ?>

+			'<?=$field;?>' => array(

+				<? if($field_type[$key]=="varchar"):?>

+					'description' => '',

+					'type' => 'varchar',

+					'length' => '255',

+					'not null' => FALSE,

+				<? elseif($field_type[$key]=="text"):?>

+					'description' => '',

+					'type' => 'text',

+					'not null' => FALSE,

+				<? elseif($field_type[$key]=="datetime"):?>

+					'description' => '',

+					'mysql_type' => 'datetime',

+					'not null' => FALSE,

+				<? elseif($field_type[$key]=="int"):?>

+					'description' => '',

+				  	'type' => 'int',

+					'default' => '0',

+					'not null' => TRUE,

+					'unsigned' => TRUE,

+				<? elseif($field_type[$key]=="tinyint"):?>

+					'description' => '',

+					'type' => 'int',

+					'size' => 'tiny',

+					'default' => '0',

+					'not null' => TRUE,

+					'unsigned' => TRUE,

+				<? endif;?>

+			),

+			<? endforeach; ?>

+		),

+		'primary key' => array('id'),

+	);

+return $schema;

+}

--- /dev/null
+++ b/tpl/crud.module.php
@@ -1,1 +1,222 @@
-
+<?="<?php";?>

+

+/**

+* Implements hook_init()

+*/

+$rows = array();

+function <?=$module_basename;?>_init(){

+

+}

+

+/**

+* Implements hook_permission()

+*/

+

+function <?=$module_basename;?>_permission(){

+	return array(

+		'access <?=$module_name;?>' =>  array(

+		'title' => t('Access <?=$module_name;?>'),

+		'description' => t('Permission for accessing the <?=$module_basename;?> module.'),

+		),

+	);

+}

+

+/**

+* Implements hook_help()

+*/

+

+function <?=$module_basename;?>_help($path, $arg){

+	switch ($path) {

+	case '<?=$module_basename;?>/manage':

+		return t('This section displays the list of <?=$module_name;?>.');

+  }

+}

+

+/**

+* Implements hook_menu()

+*/

+

+function <?=$module_basename;?>_menu(){

+	$items['<?=$module_basename;?>/summary'] = array(

+		'title' => '<?=$module_name;?>',

+		'page callback' => '<?=$module_basename;?>_summary',

+		'access arguments' => array('access <?=$module_basename;?>'),

+		'expanded' => true,

+ 	);

+	$items['<?=$module_basename;?>/update'] = array(

+		'title' => 'Toggle Status',

+		'page callback' => '<?=$module_basename;?>_update',

+		'access arguments' => array('access <?=$module_basename;?>'),

+		'expanded' => true,

+	);

+	$items['<?=$module_basename;?>/add'] = array(

+		'title' => 'Add <?=$module_name;?>',

+		'page callback' => 'drupal_get_form',

+		'page arguments' => array('<?=$module_basename;?>_add'),

+		'access arguments' => array('access <?=$module_basename;?>'),

+		'expanded' => true,

+	);

+	$items['<?=$module_basename;?>/edit'] = array(

+		'title' => 'Edit <?=$module_basename;?>',

+		'page callback' => 'drupal_get_form',

+		'page arguments' => array('<?=$module_basename;?>_edit'),

+		'access arguments' => array('access <?=$module_basename;?>'),

+		'expanded' => true,

+	);

+	$items['<?=$module_basename;?>/delete'] = array(

+		'title' => 'Delete <?=$module_name;?>',

+		'page callback' => '<?=$module_basename;?>_delete',

+		'access arguments' => array('access <?=$module_basename;?>'),

+		'expanded' => true,

+	);

+	return $items;

+}

+

+function <?=$module_basename;?>_summary($arg = 0){

+	$result = db_query("select * from `<?=$module_table;?>`");

+	$rows = array();

+	$i=0;

+	foreach ($result as $record) {

+	    $rows[] = array_map('check_plain', (array)$record);

+		if($rows[$i]['count'] > 0){

+			 $rows[$i]['name']= l($rows[$i]['name'], '<?=$module_basename;?>/summary/'.$rows[$i]['id']);

+		}

+		$rows[$i]['status'] = $rows[$i]['status']==1

+			? l(theme('image', array('path' => drupal_get_path('module','<?=$module_basename;?>').'/images/active.png', 'alt' => 'Active image', 'title' => 'Active',)),'<?=$module_basename;?>/update',array('html' => TRUE, 'query' => array('id' => $rows[$i]['id'])))

+			: l(theme('image', array('path' => drupal_get_path('module','<?=$module_basename;?>').'/images/inactive.png', 'alt' => 'Inactive image', 'title' => 'Inactive',)),'<?=$module_basename;?>/update',array('html' => TRUE, 'query' => array('id' => $rows[$i]['id'])));

+		$rows[$i]['edit'] = l('Edit', '<?=$module_basename;?>/edit', array('query' => array('id' => $rows[$i]['id'])));

+		if($rows[$i]['count'] == 0)

+			$rows[$i]['delete'] = l('Delete', '<?=$module_basename;?>/delete', array('query' => array('id' => $rows[$i]['id'])));

+		$i++;

+	}

+	$header = array(t('Id')

+	<? unset ($field_name['1']); ?>

+	<? foreach ($field_name as $key => $field): ?>

+	,t('<?=ucwords( str_replace("_", " ", $field) );?>')

+	<? endforeach; ?>

+	,t('Edit'),t('Delete'));

+	$output = theme('table', array('header' => $header, 'rows' => $rows));

+	$output .= l('Add <?=$module_name;?>', '<?=$module_basename;?>/add');

+	return $output;

+}

+

+function <?=$module_basename;?>_update(){

+	$result = db_query("update <?=$module_table;?> set status = !status where id={$_GET['id']}");

+	header("Location: summary");

+}

+

+function <?=$module_basename;?>_delete(){

+	$result = db_query("DELETE FROM <?=$module_table;?> where id={$_GET['id']}");

+	header("Location: summary");

+}

+

+function <?=$module_basename;?>_add($form, &$form_submit){

+	//$<?=$module_basename;?> = get<?=$module_basename;?>();

+

+	<? unset ($field_name['1']); ?>

+	<? foreach ($field_name as $key => $field): ?>

+		$form['<?=$field;?>'] = array(

+		'#title' => t('<?=ucwords( str_replace("_", " ", $field) );?>'),

+		<? if($field_type[$key]=="varchar"):?>

+		'#type' => 'textfield',

+		<? elseif($field_type[$key]=="text"):?>

+		'#type' => 'textarea',

+		<? else: ?>

+		'#type' => 'textfield',

+		<? endif; ?>

+		'#required' => TRUE,

+		'#description' => t(''),

+		);

+	<? endforeach; ?>

+

+	$form['submit'] = array(

+		'#type' => 'submit',

+		'#value' => 'Submit',

+	);

+	//kpr($form);

+	return $form;

+}

+

+function <?=$module_basename;?>_edit($form, &$form_submit){

+	//$<?=$module_basename;?> = get<?=$module_basename;?>();

+	if(isset($_GET['id']) && !empty($_GET['id'])){

+	$result = db_query("SELECT * FROM <?=$module_table;?> WHERE id = {$_GET['id']}");

+	$row = array();

+	foreach($result as $record){

+		$row = (array)$record;

+	}

+	}

+	$form['id'] = array(

+		'#value' => $row['id'],

+		'#type' => 'hidden',

+	);

+	<? unset ($field_name['1']); ?>

+	<? foreach ($field_name as $key => $field): ?>

+	$form['<?=$field;?>'] = array(

+		'#title' => t('<?=ucwords( str_replace("_", " ", $field) );?>'),

+  		<? if($field_type[$key]=="varchar"):?>

+		'#type' => 'textfield',

+		<? elseif($field_type[$key]=="text"):?>

+		'#type' => 'textarea',

+		<? else: ?>

+		'#type' => 'textfield',

+		<? endif; ?>

+		'#default_value' => $row['<?=$field;?>'],

+		'#required' => TRUE,

+		'#description' => t(''),

+	);

+	<? endforeach; ?>

+	$form['submit'] = array(

+		'#type' => 'submit',

+		'#value' => 'Submit',

+	);

+	//kpr($form);

+	return $form;

+}

+

+function <?=$module_basename;?>_add_submit($form, &$form_state){

+

+	<? foreach ($field_name as $key => $field): ?>

+		$<?=$field;?> = $form_state['values']['<?=$field;?>'];

+	<? endforeach; ?>

+

+	$result = db_query("INSERT INTO <?=$module_table;?>(

+	<? unset ($field_name['1']); ?>

+	<? $i=0; foreach ($field_name as $key => $field): ?>

+	<? if($i>=1):?>,<?endif;?>`<?=$field;?>`

+	<? $i++; endforeach; ?>

+	) VALUES(

+	<? $i=0; foreach ($field_name as $key => $field): ?>

+	<? if($i>=1):?>,<?endif;?>'{$<?=$field;?>}'

+	<? $i++; endforeach; ?>

+	)");

+	$form_state['redirect'] = '<?=$module_basename;?>/summary';

+}

+

+function get<?=$module_basename;?>(){

+	global $rows;

+	$result = db_query("SELECT * FROM <?=$module_table;?>");

+	$arr = array();

+	$i=0;

+	foreach ($result as $record) {

+		$record = (array)$record;

+		$arr[$record['id']] = $record;

+		$i++;

+	}

+	return $arr;

+}

+

+function <?=$module_basename;?>_edit_submit($form, &$form_state){

+	$id = $form_state['values']['id'];

+	<? foreach ($field_name as $key => $field): ?>

+		$<?=$field;?> = $form_state['values']['<?=$field;?>'];

+	<? endforeach; ?>

+

+	$result = db_query("UPDATE <?=$module_table;?> SET 1=1

+	<? unset ($field_name['1']); ?>

+	<? foreach ($field_name as $key => $field): ?>

+		,`<?=$field;?>`='{$<?=$field;?>}'

+	<? endforeach; ?>

+	WHERE id = {$id}");

+	$form_state['redirect'] = '<?=$module_basename;?>/summary';

+}

 Binary files /dev/null and b/tpl/images/active.png differ
 Binary files /dev/null and b/tpl/images/inactive.png differ
comments