PHP - Table Reordering Ala Joomla
Hey guys,
Anyone who's used Joomla will know they have a very snazzy system for allowing the user to reorder the "order" field in any given table. You know the one, the blue arrows pointing up and down to move the row up or down. I wanna implement something similar in my own sites CMS, does anyone know a good script to handle it? Similar TutorialsHi all, I'm just getting into PHP and loving it so far. I'm building my first CMS and have run into a bit of a stumper. I have categories for products and a table for each. Pretty standard. My issue is coming with a reorder of positions. I'll use my category table for this example as it's very simple. The table has an auto-incrementing id, a category name and a position. When I add a category I just do a mysql_num_rows on the table and the new category's position is that var + 1. I'm using a nice jQuery drag and drop reorder plugin and no problems there. What I'm having trouble with is when I delete a category I want to reorder the remaining ones in the table from 1 to whatever. Here's what I've come up with and it doesn't work for me. // DELETE if (isset($_POST['delete']) && isset($_POST['cat_id'])) { $cat_id = $_POST['cat_id']; $delete = "DELETE FROM categories WHERE cat_id='$cat_id' LIMIT 1"; $result_del = mysql_query($delete, $connection); confirm_query($result_del); // Reorder after delete // get all categories by position $get_cats = "SELECT * FROM categories ORDER BY position ASC"; $cats = mysql_query($get_cats, $connection); confirm_query($cats); // get number of rows in categories $rows = mysql_num_rows($result); //get ids of all categories $get_ids = "SELECT cat_id FROM categories ORDER BY position ASC"; $ids = mysql_query($get_ids, $connection); confirm_query($ids); // put id values into array $id_array = mysql_fetch_array($ids); // reorder positions for ($j = 1; $j <= $rows; ++$j) { $row = mysql_fetch_row($result); $fetch = $id_array[$j-1]; $query1 = "UPDATE categories SET position='$j' WHERE cat_id='$fetch'"; $result1 = mysql_query($query1, $connection); confirm_query($result1); } } I've been going over and over this for a couple days and just can't seem to get it. Any help would be really appreciated! I have a question about reordering an array. When I print the array it looks like this: Quote Array ( [1] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 5 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 271.25 ) [2] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 3 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 162.75 ) ) Now if I delete an entry or 2 it looks like this: Quote Array ( [3] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 5 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 271.25 ) [6] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 3 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 162.75 ) ) Is it possible to get the arrays to reorder so that the values are [1] and [2] again? I tried this: array_values($_SESSION['Array']); But it doesn't do anything for some reason Hello all,
I have a question. The server I am currently working on is on PHP 5.2 and Joomla 1.5.26. I'd like to migrate or slowly move over to 3.0 on the same server however 3.0 requires at least 5.3 (would go to 5.4). In my cpanel, it tells me "PHP 5.4+ Incompatible Applications Installed". Is it not possible to run Joomla 1.5 on PHP 5.4, or are there certain components/modules that do not work with it?
The two major third party components I have installed are Community Builder and Jumi.
I just don't want my site to explode if I click the button.
Thanks,
Rob
Edited by Spikes, 10 November 2014 - 10:21 PM. Hi ,
My site gives a blank page when i click on an article due to insufficient memory. I tried making changes to the php.ini file but the changes are not getting reflected.
Please advice if a server restart is needed for this, how do i go about it?
Thanks in advance
I'm using the J2Store add-on for Joomla. The store prints out a invoice and I am editing what prints out. Right now it prints out each item ordered and the 'options' with that item. (Ex. You can order a Large shirt the options are its a t-shirt and blue.)
What I'm trying to do is make a list of all the material ('options') and quanities in each order.
Below is the section of code I have been working with. I added '<?php echo count($item); ?>' to the code but it just lists the 'options' then a 1 after, but only for one item in the order.
The J2Store support told me this:
"
first you need to decode the $item->orderitem_attributes Then you need to parse through the array and get the options in a required format by sorting and using multiple loops. Then count each option. Example count($array['large']); " <?php if(!J2StoreOrdersHelper::isJSON(stripslashes($item->orderitem_attribute_names))): ?> <?php if (!empty($item->orderitem_attribute_names)) : ?> <span><?php echo $item->orderitem_attribute_names; ?></span> <?php endif; ?> <br /> <?php else: ?> <!-- since 3.1.0. Parse attributes that are saved in JSON format --> <?php if (!empty($item->orderitem_attribute_names)) : ?> <?php //first convert from JSON to array $registry = new JRegistry; $registry->loadString(stripslashes($item->orderitem_attribute_names), 'JSON'); $product_options = $registry->toObject(); ?> <?php foreach ($product_options as $option) : ?> - <small> <?php echo JText::_($option->name); ?>: <?php echo JText::_($option->value); ?> <?php echo count($item); ?> <?php if(isset($option->option_sku) && JString::strlen($option->option_sku) > 0):?> (<?php echo JText::_('J2STORE_SKU'); ?> : <?php echo $option->option_sku; ?>) <?php endif; ?> </small><br /> <?php endforeach; ?> <br/> <?php endif; ?> <?php endif; ?> Edited by Zane, 23 May 2014 - 11:59 AM. A joomla module have the following code which displays the date of an article, and to a seperate line the linked title of that article.
Please help me on how to change that code so that the date and the title of the article to be presented in the same line?
<div class="smartlatest-title"> <?php if($params->get('show_date',1)) echo '<div class="smartlatest-date">'.strftime($params->get('date_format','%d-%m-%Y'), strtotime($item->publish_up)).'</div>'; ?> <?php if($params->get('link_title',1)) { ?><a href="<?php echo $item->link; ?>" class="smartlatest-title-link"><?php } ?> <?php echo $item->title; ?> <?php if($params->get('link_title',1)) { ?></a><?php } ?> </div> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=306933.0 Hi I am trying to knock up a script to create a userid and log someone into a Joomla based site. The script is running on the same server as the site (and is legitimate, not nefarious). I can create an ID OK, and I can retrieve the login page, scrape the details (including the token) and submit the form. When I do this the user is logged in according to the Joomla sessions table, but it has also created a 2nd guest session there. Navigating to the Joomla site (either manually or doing a header redirect) just takes you to the site as though you are not logged in. Code as it stands (and code to deal with being passed user ids and passwords will change to be at least vaguely secure, just trying to get things to work now) Code: [Select] <?php session_start(); session_regenerate_id(); require("configuration.php"); $ConfigDetails = new JConfig(); $dbms = $ConfigDetails->dbtype; $dbhost = $ConfigDetails->host; $dbname = $ConfigDetails->db; $dbuser = $ConfigDetails->user; $dbpasswd = $ConfigDetails->password; $salt = 'somesalt'; $url = "http://localhost/joomla/index.php"; $IncomingUid = $_REQUEST['uid']; $IncomingName = $_REQUEST['name']; $IncomingPassword = $_REQUEST['pwd']; $IncomingEmail = $_REQUEST['email']; // Make the database connection. $SurveyConn = mysql_connect($dbhost,$dbuser,$dbpasswd); mysql_select_db($dbname,$SurveyConn) or die(mysql_error()); $sql = "SELECT * FROM ".$ConfigDetails->dbprefix."users WHERE username = '".mysql_real_escape_string($IncomingUid)."'"; $rs = mysql_query($sql) or die(mysql_error()); if ($row = mysql_fetch_assoc($rs)) { if ($IncomingPassword == $row['password']) { } } else { $PasswordEncrypted = md5($IncomingPassword.$salt).':'.$salt; $sqli = "INSERT INTO ".$ConfigDetails->dbprefix."users (id, name, username, email, password, usertype, block, sendEmail, registerDate, lastvisitDate, activation, params) VALUES(NULL, '".mysql_real_escape_string($IncomingName)."','".mysql_real_escape_string($IncomingUid)."','".mysql_real_escape_string($IncomingEmail)."','".mysql_real_escape_string($PasswordEncrypted)."','deprecated',0,1,NOW(), NOW(), '', '')"; $rs = mysql_query($sqli) or die(mysql_error()." $sqli"); $sqli = "INSERT INTO ".$ConfigDetails->dbprefix."user_usergroup_map (user_id, group_id) VALUES(".mysql_insert_id().", 8)"; $rs = mysql_query($sqli) or die(mysql_error()." $sqli"); } $agent = "'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6'"; $c1 = curl_init(); curl_setopt($c1, CURLOPT_URL, $url ); curl_setopt($c1, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt($c1, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt($c1, CURLOPT_VERBOSE, 1); curl_setopt($c1, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($c1, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($c1, CURLOPT_USERAGENT, $agent ); curl_setopt($c1, CURLOPT_HEADER, TRUE ); curl_setopt($c1, CURLOPT_REFERER, $url1); curl_setopt($c1, CURLOPT_POST, 1); $html = curl_exec($c1); $dom = new DOMDocument(); $FormFieldsArray = array(); if (@$dom->loadHTML($html)) { // yep, not necessarily valid-html... $xpath = new DOMXpath($dom); $nodeListInputs = $xpath->query('//input'); if ($nodeListInputs->length > 0) { $FormFieldsArray = array(); for ($i=0 ; $i<$nodeListInputs->length ; $i++) { $nodeInput = $nodeListInputs->item($i); $name = $nodeInput->getAttribute('name'); $value = $nodeInput->getAttribute('value'); $FormFieldsArray[$name] = $value; } } } else { // too bad... } if (count($FormFieldsArray) > 0) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_USERAGENT, $agent ); curl_setopt($ch, CURLOPT_HEADER, TRUE ); curl_setopt($ch, CURLOPT_REFERER, $url1); // POST fields $postfields = array(); foreach($FormFieldsArray AS $FormFieldName=>$FormFieldValue) { switch ($FormFieldName) { case 'username' : $postfields['username'] = urlencode($IncomingUid); break; case 'passwd' : $postfields['passwd'] = urlencode($IncomingPassword); break; case 'password' : $postfields['password'] = urlencode($IncomingPassword); break; default : $postfields[$FormFieldName] = $FormFieldValue; break; } } curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $ret = curl_exec($ch); // Get logged in cookie and pass it to the browser preg_match('/^Set-Cookie: (.*?);/m', $ret, $m); $cookie = explode('=', $m[1]); setcookie($cookie[0], $cookie[1]); header("location: ".$url); } //echo $ret; ?> Any ideas? All the best Keith Hi there,
I have decided using the Joomla API however, the documentation was for 1.5 and 2.5 system only but i'm using 3.0. I have a number of files that look like this:
"14-05-14 JoePharnel.pdf"
and
"13-05-12 HarryCollins.pdf"
Basically I want to create a PHP code that when someone ftp uploads those files to the upload folder that it will 1) Create a directory if it doesn't exist using there name 2) Move the files to the correct directory (E.g. JoePharnel to the JoePharnel Directory ignoring the number at the beginning)
My new code creates the folder but won't move the file in the upload into that new folder, code is below:
<?php define( '_JEXEC', 1); define('JPATH', dirname(__FILE__) ); if (!defined('DS')){ define( 'DS', DIRECTORY_SEPARATOR ); $parts = explode( DS, JPATH ); $script_root = implode( DS, $parts ) ; // check path $x = array_search ( 'administrator', $parts ); if (!$x) exit; $path = ''; for ($i=0; $i < $x; $i++){ $path = $path.$parts[$i].DS; } // remove last DS $path = substr($path, 0, -1); if (!defined('JPATH_BASE')){ define('JPATH_BASE', $path ); } if (!defined('JPATH_SITE')){ define('JPATH_SITE', $path ); } /* Required Files */ require_once ( JPATH_SITE . DS . 'includes' . DS . 'defines.php' ); require_once ( JPATH_SITE . DS . 'includes' . DS . 'framework.php' ); require_once ( JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' ); //Import filesystem libraries. Perhaps not necessary, but does not hurt jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.user.user'); //First we set up parameters $searchpath = JPATH_BASE . DS . "upload"; //Then we create the subfolder called png if ( !JFolder::create($searchpath . DS ."Images") ) { //Throw error message and stop script } //Now we read all png files and put them in an array. $png_files = JFolder::files($searchpath,'.png'); //Now we need some stuff from the JFile:: class to move all files into the new folder foreach ($png_files as $file) { JFile::move($searchpath. DS . ".png" . $file, $searchpath . DS. "Images" . $file); } //Lastly, we are moving the complete subdir to the root of the component. if (JFolder::move($searchpath . DS. "Images",JPATH_COMPONENT) ) { //Redirect with perhaps a happy message } else { //Throw an error } } ?> Only error i get is Notice: Use of undefined constant JPATH_COMPONENT - assumed 'JPATH_COMPONENT' in /upload.php on line 70. I have used and adapted multiple php code so any help would be appreciated. Or if you can point me to where i can find the answer that would be brilliant Hello, I'm trying to implement a custom css style for each of the K2 templates.
I wrote a com_K2 override.
I add this string to a K2 template php files
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/html/com_k2/templates/default/k2c.css" type="text/css" />but it adds itself in the body of the page. Is there a way to put this string into <head> tag? I'm not savvy in PHP, so any advice would be appreciated HI All,
I need some suggestions on how to proceed on with component development. and any logic code or similar coding will be very much appreciated.
The component should display the list of contents displaying some columns from a table(ie.,scncontent) from database similar to web links component along with the tool bar (new,edit,publish,unpublish,trash etc., actions ) and with pagination also . This component should be designed with MVC architecture. On clicking new or edit icons, a form should be opened and data should be saved or updated to database.
This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=314053.0 I'm trying to implement a library which was written for PSR-0 compliant autoloading in my joomla project. However joomla 2.5 does not support PSR-0 autoloading so I figured that I would have to write my own implementation.
Since I want to use my classes across my entire joomla installation I decided to write a plugin which registers the classes onAfterInitialise() but this is where it goes wrong: it overrides joomla's autoloading methods.
The library i'm trying to implement is located at libraries/Zoho/CRM/ZohoClient.php with several subfolders. Everything is namespaced with accordance to PSR-0 so starting with: \Zoho\CRM.
How do I register the classes in such a way that I can use them globally across joomla? This is my implementation:
public function onAfterInitialise() { spl_autoload_register(function ($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; }); }This obviously wont work because it overrides the joomla autoloading function. I'm running php5.3 (5.4 in 3 months) This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=328109.0 I have a php page that is linked to in a Joomla site in a Wrapper. I want to be able to block access to a php page unless it was called by a link in the main menu. I figured I could use $_SERVER['HTTP_REFERER'] to accomplish this like so: Link from Main Menu -> top_secret.php Code: [Select] <?php //the following is placed in the header of top_secret.php web page $page1 = 'http://myweb.com/index.php?option=com_wrapper&view=wrapper&Itemid=201';//page that user must come from $menu_link = $_SERVER['HTTP_REFERER'];//page that user comes from if($page1 !== $menu_link) { header('Location: http://myweb.com/error_page.php'); } ?> Thus if some one tries to simply access the top_secret.php with out going through the joomla menu- they will be re-directed to an error page. My question to the guru's is- is this secure or can someone easily get to the top_secret.php without going through the menu. Keep in mind- that the menu the person must use is only accessible from a registered joomla user for that site. Hope that makes sense. I want to move a module, as shown in the attached jpeg. I want to move it to the position illustrated by the arrow, and I want to increase it's height so it fills the space but leaving a border. There is no module in the position that I can use, so I have to adjust the html coding (I presume). Can anyone help me with this? I have searched for help and I don't even know which file I need to change - whether it is the css or the html. Cheers, James. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=346951.0 Hi Friends..... I want to implement search indexing (like joomla) in my website. Earlier I develop search from database by "select" statement. But for whole website, I don't have any idea to do it............ Plzzzzzzz Help ??????/// I'll highly oblized to you............. Hi. We have a Joomla Site with a SMF forum (Simple Machine Forum). And with php, we load the 10 recent topics in a module in Joomla. So when someone click the URLs from the 10 recent topics clicked, we hope that those URLs will open in the "wrapper" in Joomla The "wrapper" constantly have this URL: http://localhost/~2ms/FFS-VPS/index.php?option=com_wrapper&view=wrapper&Itemid=148 The URLs of the recent topics are always changing (dynamicly). In a php file called "recentTopics.php" we have this php: <?php require("/Users/2ms/Sites/FFS-VPS/latin1/SSI.php"); ?> <?php ssi_recentTopics(10); ?> The first php script points to the SSI.php file in the SMF directory and the second pic up the 10 recent topics and shows those in a module pointing to the "recentTopics.php file in Joomla. Hope someone can help. toloekka |