Created
September 7, 2010 11:36
-
-
Save juanramon/568199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
function checkAll (frm, check) { | |
var aa = document.getElementById(frm); | |
for (var i = 0 ; i < aa.elements.length ; i++) { | |
aa.elements[i].checked = check; | |
} | |
} | |
function checkCat(id, check) { | |
var lay = document.getElementById("cat" + id); | |
inp = lay.getElementsByTagName("input"); | |
for (var i = 0, maxI = inp.length ; i < maxI; ++i) | |
{ | |
if(inp[i].type == "checkbox") | |
{ | |
inp[i].checked = check; | |
} | |
} | |
} | |
</script> | |
<form id="frm3" action="plugins.php" method="post"> | |
<input type="hidden" name="action" value="admin_post" /> | |
<input type="hidden" name="plugin" value="books_attributes" /> | |
The plugin <strong>TextBooks attributes</strong> adds a set of attributes to the categories you choose. Please select here all the categories where apply these attributes: | |
<p> | |
<?php $numCols = 1; ?> | |
<?php $catsPerCol = round(count($categories)/$numCols) ; ?> | |
<table> | |
<tr style="vertical-align: top;"> | |
<td style="font-weight: bold;" colspan="<?php echo $numCols; ?>"> | |
<label for="categories">Presets categories</label><br /> | |
<a style="font-size: x-small; color: gray;" href="#" onclick="checkAll('frm3', true); return false;">Check all</a> - <a style="font-size: x-small; color: gray;" href="#" onclick="checkAll('frm3', false); return false;">Uncheck all</a> | |
</td> | |
<?php for ($j = 0 ; $j < $numCols ; $j++) {?> | |
<td> | |
<?php for ($i = $catsPerCol*$j ; $i < $catsPerCol*($j+1) ; $i++) {?> | |
<?php if (is_array($categories[$i])) {?> | |
<br /><input type="checkbox" name="categories[]" value="<?php echo $categories[$i]['pk_i_id']; ?>" style="float:left;" onclick="javascript:checkCat('<?php echo $categories[$i]['pk_i_id'];?>', this.checked);"><span style="font-size:25px"><?php echo $categories[$i]['s_name']; ?></span></input><br /> | |
<div id="cat<?php echo $categories[$i]['pk_i_id'];?>"> | |
<?php foreach($categories[$i]['categories'] as $sc): ?> | |
<input type="checkbox" name="categories[]" value="<?php echo $sc['pk_i_id']; ?>"><?php echo $sc['s_name']; ?></input><br /> | |
<?php endforeach; ?> | |
</div> | |
<?php } ?> | |
<?php } ?> | |
</td> | |
<?php } ?> | |
</tr> | |
</table> | |
</p> | |
<p> | |
<input class="Button" type="button" onclick="window.history.go(-1);" value="<?php echo __('Cancel'); ?>" /> | |
<input class="Button" type="submit" value="<?php echo __('Save'); ?>" /> | |
</p> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$GLOBALS['booksAttributesData'] = array( | |
's_section' => 'books_attributes', | |
's_name' => 'installed', | |
's_value' => 'true', | |
'e_type' => 'BOOLEAN' | |
); | |
$GLOBALS['textbooksAttributesData'] = array( | |
's_section' => 'textbooks_attributes', | |
's_name' => 'installed', | |
's_value' => 'true', | |
'e_type' => 'BOOLEAN' | |
); | |
function books_attributes_info() { | |
return array( | |
'name' => 'Books megaplugin', | |
'description' => 'This plugin does a lot of fancy stuff, just for your information. I just added some sparky rainbows and unicorns to make it f*cking awesome!', | |
'version' => 0.1, | |
'author_name' => 'Daniel Esteban', | |
'author_url' => 'http://www.theninjabunny.com/', | |
'hooks' => array('admin', 'install', 'uninstall') | |
); | |
} | |
function books_attributes_is_installed() { | |
global $booksAttributesData; | |
return Preference::newInstance()->exists($booksAttributesData); | |
} | |
function books_attributes_install() { | |
require_once 'osclass/classes/DAO.php'; | |
require_once 'osclass/model/Preference.php'; | |
global $db, $booksAttributesData; | |
$db->autocommit(false); | |
try { | |
$path = osc_pluginResource('books_attributes/struct.sql'); | |
$sql = file_get_contents($path); | |
osc_dbImportSQL($sql); | |
Preference::newInstance()->insert($booksAttributesData); | |
$db->commit(); | |
} catch (DatabaseException $e) { | |
$db->rollback(); | |
$e->getMessage(); | |
} | |
$db->autocommit(true); | |
} | |
function books_attributes_uninstall() { | |
require_once 'osclass/classes/DAO.php'; | |
require_once 'osclass/model/Preference.php'; | |
global $db, $booksAttributesData, $textbooksAttributesData; | |
$db->autocommit(false); | |
try { | |
osc_dbExec('DROP TABLE %st_item_book_attr', DB_TABLE_PREFIX); | |
Preference::newInstance()->delete($booksAttributesData); | |
$db->commit(); | |
osc_dbExec('DROP TABLE %st_item_textbook_attr', DB_TABLE_PREFIX); | |
Preference::newInstance()->delete($textbooksAttributesData); | |
$db->commit(); | |
} catch (DatabaseException $e) { | |
$db->rollback(); | |
$e->getMessage(); | |
} | |
$db->autocommit(true); | |
} | |
function books_attributes_item_detail($item) { | |
$detail = osc_dbFetchResult("SELECT * FROM %st_item_book_attr WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item['pk_i_id']); | |
require 'item_detail.php'; | |
} | |
function books_attributes_admin() { | |
require_once 'osclass/model/Category.php'; | |
$categories = Category::newInstance()->toTree(); | |
$selected = osc_dbFetchValues("SELECT fk_i_category_id FROM %st_plugin_category WHERE s_plugin_name = 'books_attributes'", DB_TABLE_PREFIX); | |
require 'admin.php'; | |
} | |
function books_attributes_insertRecursive($catsId) { | |
foreach($catsId as $catId) { | |
osc_dbExec("INSERT INTO %st_plugin_category VALUES ('books_attributes', %d)", DB_TABLE_PREFIX, $catId); | |
books_attributes_insertRecursive(osc_dbFetchValues('SELECT pk_i_id FROM %st_category WHERE fk_i_parent_id = %d', DB_TABLE_PREFIX, $catId)); | |
} | |
} | |
function books_attributes_admin_post() { | |
osc_dbExec("DELETE FROM %st_plugin_category WHERE s_plugin_name = 'books_attributes'", DB_TABLE_PREFIX); | |
if(isset($_POST['categories'])) | |
books_attributes_insertRecursive($_POST['categories']); | |
} | |
function books_attributes_form() { | |
require 'form.php'; | |
} | |
function books_attributes_search_form() { | |
ob_start(); | |
require 'search_form.php'; | |
return ob_get_clean(); | |
} | |
function books_attributes_search_conditions($params) { | |
$conditions = array(); | |
foreach($params as $key => $value) { | |
switch($key) { | |
case 'editorial': | |
$conditions[] = sprintf("%st_item_book_attr.s_editorial LIKE '%%%s%%' ", DB_TABLE_PREFIX, $value); | |
break; | |
case 'subtitle': | |
$conditions[] = sprintf("%st_item_book_attr.s_subtitle LIKE '%%%s%%' ", DB_TABLE_PREFIX, $value); | |
break; | |
case 'author': | |
$conditions[] = sprintf("%st_item_book_attr.s_author LIKE '%%%s%%' ", DB_TABLE_PREFIX, $value); | |
break; | |
case 'year': | |
$conditions[] = sprintf("%st_item_book_attr.i_year LIKE '%%%s%%' ", DB_TABLE_PREFIX, $value); | |
break; | |
case 'isbn': | |
$conditions[] = sprintf("%st_item_book_attr.i_isbn LIKE '%%%s%%' ", DB_TABLE_PREFIX, $value); | |
break; | |
case 'edition': | |
$conditions[] = sprintf("%st_item_book_attr.i_edition LIKE '%%%s%%' ", DB_TABLE_PREFIX, $value); | |
break; | |
case 'condition': | |
if($value!='ANY') { | |
$conditions[] = sprintf("%st_item_book_attr.e_condition LIKE '%%%s%%' ", DB_TABLE_PREFIX, $value); | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
return $conditions; | |
} | |
function books_attributes_search_table() { | |
return sprintf("%st_item_book_attr", DB_TABLE_PREFIX); | |
} | |
function books_attributes_form_post($item) { | |
osc_dbExec("INSERT INTO %st_item_book_attr (fk_i_item_id, s_editorial, s_subtitle, s_author, i_isbn, i_year, i_edition, e_condition) VALUES (%d, '%s', '%s', '%s', %d, %d, %d, '%s')", | |
DB_TABLE_PREFIX, | |
$item['id'], | |
$_POST['editorial'], | |
$_POST['subtitle'], | |
$_POST['author'], | |
$_POST['isbn'], | |
$_POST['year'], | |
$_POST['edition'], | |
$_POST['condition'] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment