Created
September 7, 2010 11:39
-
-
Save juanramon/568201 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="textbooks_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['textbooksAttributesData'] = array( | |
's_section' => 'textbooks_attributes', | |
's_name' => 'installed', | |
's_value' => 'true', | |
'e_type' => 'BOOLEAN' | |
); | |
//ID To check for the Books Plugin | |
$GLOBALS['booksAttributesData'] = array( | |
's_section' => 'books_attributes', | |
's_name' => 'installed', | |
's_value' => 'true', | |
'e_type' => 'BOOLEAN' | |
); | |
function textbooks_attributes_info() { | |
return array( | |
'name' => 'Textbooks megaplugin', | |
'description' => 'Even more awesome than the books megaplugin. Hey Fancy Warrior! Books megaplugin is REQUIRED for this one to work, FYI.', | |
'version' => 0.1, | |
'author_name' => 'Daniel Esteban', | |
'author_url' => 'http://www.theninjabunny.com/', | |
'hooks' => array('admin', 'install', 'uninstall') | |
); | |
} | |
function textbooks_attributes_is_installed() { | |
global $textbooksAttributesData; | |
return Preference::newInstance()->exists($textbooksAttributesData); | |
} | |
function textbooks_attributes_install() { | |
require_once 'osclass/classes/DAO.php'; | |
require_once 'osclass/model/Preference.php'; | |
global $db, $textbooksAttributesData, $booksAttributesData; | |
if(Preference::newInstance()->exists($booksAttributesData)) { | |
$db->autocommit(false); | |
try { | |
$path = osc_pluginResource('textbooks_attributes/struct.sql'); | |
$sql = file_get_contents($path); | |
osc_dbImportSQL($sql); | |
Preference::newInstance()->insert($textbooksAttributesData); | |
$db->commit(); | |
} catch (DatabaseException $e) { | |
$db->rollback(); | |
$e->getMessage(); | |
} | |
$db->autocommit(true); | |
} else { | |
echo "Not so fast, my fatty unicorn. You're missing Books megaplugin ( http://www.theninjabunny.com/ ), please install it before attempting to use Textbook megaplugin."; | |
} | |
} | |
function textbooks_attributes_uninstall() { | |
require_once 'osclass/classes/DAO.php'; | |
require_once 'osclass/model/Preference.php'; | |
global $db, $textbooksAttributesData; | |
$db->autocommit(false); | |
try { | |
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 textbooks_attributes_item_detail($item) { | |
$detail = osc_dbFetchResult("SELECT * FROM %st_item_textbook_attr WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item['pk_i_id']); | |
require 'item_detail.php'; | |
} | |
function textbooks_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 = 'textbooks_attributes'", DB_TABLE_PREFIX); | |
require 'admin.php'; | |
} | |
function textbooks_attributes_insertRecursive($catsId) { | |
foreach($catsId as $catId) { | |
osc_dbExec("INSERT INTO %st_plugin_category VALUES ('books_attributes', %d)", DB_TABLE_PREFIX, $catId); | |
osc_dbExec("INSERT INTO %st_plugin_category VALUES ('textbooks_attributes', %d)", DB_TABLE_PREFIX, $catId); | |
textbooks_attributes_insertRecursive(osc_dbFetchValues('SELECT pk_i_id FROM %st_category WHERE fk_i_parent_id = %d', DB_TABLE_PREFIX, $catId)); | |
} | |
} | |
function textbooks_attributes_admin_post() { | |
osc_dbExec("DELETE FROM %st_plugin_category WHERE s_plugin_name = 'textbooks_attributes'", DB_TABLE_PREFIX); | |
if(isset($_POST['categories'])) | |
textbooks_attributes_insertRecursive($_POST['categories']); | |
} | |
function textbooks_attributes_form() { | |
require 'form.php'; | |
} | |
function textbooks_attributes_form_post($item) { | |
osc_dbExec("INSERT INTO %st_item_textbook_attr (fk_i_item_id, i_course_year, s_course, b_workbook) VALUES (%d, %d, '%s', %d)", | |
DB_TABLE_PREFIX, | |
$item['id'], | |
$_POST['course_year'], | |
$_POST['course'], | |
$_POST['workbook'] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment