PageRenderTime 56ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_virtuemart/classes/htmlTools.class.new.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 1453 lines | 1349 code | 10 blank | 94 comment | 15 complexity | 9999ab79612a86274577b4401c5d63b1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. * This file contains functions and classes for common html tasks
  5. *
  6. * @version $Id: htmlTools.class.php 1379 2008-04-21 17:44:44Z soeren_nb $
  7. * @package VirtueMart
  8. * @subpackage classes
  9. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  10. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  11. * VirtueMart is free software. This version may have been modified pursuant
  12. * to the GNU General Public License, and as distributed it includes or
  13. * is derivative of works licensed under the GNU General Public License or
  14. * other free or open source software licenses.
  15. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  16. *
  17. * http://virtuemart.net
  18. */
  19. /**
  20. * This is the class for creating administration lists
  21. *
  22. * Usage:
  23. * require_once( CLASSPATH . "pageNavigation.class.php" );
  24. * require_once( CLASSPATH . "htmlTools.class.php" );
  25. * // Create the Page Navigation
  26. * $pageNav = new vmPageNav( $num_rows, $limitstart, $limit );
  27. *
  28. * // Create the List Object with page navigation
  29. * $listObj = new listFactory( $pageNav );
  30. *
  31. * // print out the search field and a list heading
  32. * $listObj->writeSearchHeader($VM_LANG->_('PHPSHOP_PRODUCT_LIST_LBL'), IMAGEURL."ps_image/product_code.png", $modulename, "product_list");
  33. *
  34. * // start the list table
  35. * $listObj->startTable();
  36. *
  37. * // these are the columns in the table
  38. * $columns = Array( "#" => "width=\"20\"",
  39. * "<input type=\"checkbox\" name=\"toggle\" value=\"\" onclick=\"checkAll(".$num_rows.")\" />" => "width=\"20\"",*
  40. * $VM_LANG->_('PHPSHOP_PRODUCT_LIST_NAME') => '',
  41. * $VM_LANG->_('PHPSHOP_PRODUCT_LIST_SKU') => '',
  42. * _E_REMOVE => "width=\"5%\""
  43. * );
  44. * $listObj->writeTableHeader( $columns );
  45. *
  46. * ###BEGIN LOOPING THROUGH RECORDS ##########
  47. *
  48. * $listObj->newRow();
  49. *
  50. * // The row number
  51. * $listObj->addCell( $pageNav->rowNumber( $i ) );
  52. *
  53. * // The Checkbox
  54. * $listObj->addCell( mosHTML::idBox( $i, $db->f("product_id"), false, "product_id" ) );
  55. * ...
  56. * ###FINISH THE RECENT LOOP########
  57. * $listObj->addCell( $ps_html->deleteButton( "product_id", $db->f("product_id"), "productDelete", $keyword, $limitstart ) );
  58. *
  59. * $i++;
  60. *
  61. * ####
  62. * $listObj->writeTable();
  63. * $listObj->endTable();
  64. * $listObj->writeFooter( $keyword );
  65. *
  66. * @package VirtueMart
  67. * @subpackage Classes
  68. * @author soeren
  69. */
  70. class listFactory {
  71. /** @var int the number of columns in the table */
  72. var $columnCount = 0;
  73. /** @var array css classes for alternating rows (row0 and row1 ) */
  74. var $alternateColors;
  75. /** @var int The column number */
  76. var $x = -1;
  77. /** @var int The row number */
  78. var $y = -1;
  79. /** @var array The table cells */
  80. var $cells = Array();
  81. /** @var vmPageNavigation The Page Navigation Object */
  82. var $pageNav;
  83. /** @var int The smallest number of results that shows the page navigation */
  84. var $_resultsToShowPageNav = 6;
  85. function listFactory( $pageNav=null ) {
  86. if( defined('_VM_IS_BACKEND')) {
  87. $this->alternateColors = array( 0 => 'row0', 1 => 'row1' );
  88. }
  89. else {
  90. $this->alternateColors = array( 0 => 'sectiontableentry1', 1 => 'sectiontableentry2' );
  91. }
  92. $this->pageNav = $pageNav;
  93. }
  94. /**
  95. * Writes the start of the button bar table
  96. */
  97. function startTable() {
  98. ?><script type="text/javascript"><!--
  99. function MM_swapImgRestore() { //v3.0
  100. var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  101. } //-->
  102. </script>
  103. <table class="adminlist" width="100%">
  104. <?php
  105. }
  106. /**
  107. * writes the table header cells
  108. * Array $columnNames["Product Name"] = "class=\"small\" id=\"bla\"
  109. */
  110. function writeTableHeader( $columnNames ) {
  111. if( !is_array( $columnNames ))
  112. $this->columnCount = intval( $columnNames );
  113. else {
  114. $this->columnCount = count( $columnNames );
  115. echo '<tr>';
  116. foreach( $columnNames as $name => $attributes ) {
  117. $name = html_entity_decode( $name );
  118. echo "<th class=\"title\" $attributes>$name</th>\n";
  119. }
  120. echo "</tr>\n";
  121. }
  122. }
  123. /**
  124. * Adds a new row to the list
  125. *
  126. * @param string $class The additional CSS class name
  127. * @param string $id The ID of the HTML tr element
  128. * @param string $attributes Additional HTML attributes for the tr element
  129. */
  130. function newRow( $class='', $id='', $attributes='') {
  131. $this->y++;
  132. $this->x = 0;
  133. if( $class != '') {
  134. $this->cells[$this->y]['class'] = $class;
  135. }
  136. if( $id != '') {
  137. $this->cells[$this->y]['id'] = $id;
  138. }
  139. if( $attributes != '' ) {
  140. $this->cells[$this->y]['attributes'] = $attributes;
  141. }
  142. }
  143. function addCell( $data, $attributes="" ) {
  144. $this->cells[$this->y][$this->x]["data"] = $data;
  145. $this->cells[$this->y][$this->x]["attributes"] = $attributes;
  146. $this->x++;
  147. }
  148. /**
  149. * Writes a table row with data
  150. * Array
  151. * $row[0]["data"] = "Cell Value";
  152. * $row[0]["attributes"] = "align=\"center\"";
  153. */
  154. function writeTable() {
  155. if( !is_array( $this->cells ))
  156. return false;
  157. else {
  158. $i = 0;
  159. foreach( $this->cells as $row ) {
  160. echo "<tr class=\"".$this->alternateColors[$i];
  161. if( !empty($row['class'])) {
  162. echo ' '.$row['class'];
  163. }
  164. echo '"';
  165. if( !empty($row['id'])) {
  166. echo ' id="'.$row['id'].'" ';
  167. }
  168. if( !empty($row['attributes'])) {
  169. echo $row['attributes'];
  170. }
  171. echo ">\n";
  172. foreach( $row as $cell ) {
  173. if( $cell["data"] == 'i' || !isset( $cell["data"] ) || !is_array($cell)) continue;
  174. $value = $cell["data"];
  175. $attributes = $cell["attributes"];
  176. echo "<td $attributes>$value</td>\n";
  177. }
  178. echo "</tr>\n";
  179. $i == 0 ? $i++ : $i--;
  180. }
  181. }
  182. }
  183. function endTable() {
  184. echo "</table>\n";
  185. }
  186. /**
  187. * This creates a header above the list table, containing a search box
  188. * @param The Label for the list (will be used as list heading!)
  189. * @param The core module name (e.g. "product")
  190. * @param The page name (e.g. "product_list" )
  191. * @param Additional varaibles to include as hidden input fields
  192. */
  193. function writeSearchHeader( $title, $image="", $modulename, $pagename) {
  194. global $sess, $keyword, $VM_LANG;
  195. if( !empty( $keyword )) {
  196. $keyword = urldecode( $keyword );
  197. }
  198. else {
  199. $keyword = "";
  200. }
  201. $search_date = vmGet( $_REQUEST, 'search_date', null);
  202. $show = vmGet( $_REQUEST, "show", "" );
  203. $header = '<a name="listheader"></a>';
  204. $header .= '<form name="adminForm" action="'.$_SERVER['PHP_SELF'].'" method="post">
  205. <input type="hidden" name="option" value="'.VM_COMPONENT_NAME.'" />
  206. <input type="hidden" name="page" value="'. $modulename . '.' . $pagename . '" />
  207. <input type="hidden" name="task" value="" />
  208. <input type="hidden" name="func" value="" />
  209. <input type="hidden" name="vmtoken" value="'.vmSpoofValue($sess->getSessionId()).'" />
  210. <input type="hidden" name="no_menu" value="'.vmRequest::getInt( 'no_menu' ).'" />
  211. <input type="hidden" name="no_toolbar" value="'.vmRequest::getInt('no_toolbar').'" />
  212. <input type="hidden" name="only_page" value="'.vmRequest::getInt('only_page').'" />
  213. <input type="hidden" name="boxchecked" />';
  214. if( defined( "_VM_IS_BACKEND") || @$_REQUEST['pshop_mode'] == "admin" ) {
  215. $header .= "<input type=\"hidden\" name=\"pshop_mode\" value=\"admin\" />\n";
  216. }
  217. $header .= '<table class="admin_heading"><tr><td>';
  218. if( $title != "" ) {
  219. $style = ($image != '') ? 'style="background:url('.$image.') no-repeat;text-indent: 30px;line-height: 50px;"' : '';
  220. $header .= '<div class="header" '.$style.'><h2 style="margin: 0px;">'.$title.'</h2></div></td>'."\n";
  221. $GLOBALS['vm_mainframe']->setPageTitle( $title );
  222. }
  223. if( !empty( $pagename ))
  224. $header .= '<td width="20%" class="search_form">
  225. <input class="inputbox" type="text" size="25" name="keyword" value="'.shopMakeHtmlSafe($keyword).'" />
  226. <input class="button" type="submit" name="search" value="'.$VM_LANG->_('PHPSHOP_SEARCH_TITLE').'" />
  227. </td>';
  228. $header .= "\n</tr></table><br style=\"clear:both;\" />\n";
  229. if ( !empty($search_date) ) // Changed search by date
  230. $header .= '<input type="hidden" name="search_date" value="'.$search_date.'" />';
  231. if( !empty($show) ) {
  232. $header .= "<input type=\"hidden\" name=\"show\" value=\"$show\" />\n";
  233. }
  234. echo $header;
  235. }
  236. /**
  237. * This creates a list footer (page navigation)
  238. * @param The core module name (e.g. "product")
  239. * @param The page name (e.g. "product_list" )
  240. * @param The Keyword from a search by keyword
  241. * @param Additional varaibles to include as hidden input fields
  242. */
  243. function writeFooter($keyword, $extra="") {
  244. $footer= "";
  245. if( $this->pageNav !== null ) {
  246. if( $this->_resultsToShowPageNav <= $this->pageNav->total ) {
  247. $footer = $this->pageNav->getListFooter();
  248. }
  249. }
  250. else {
  251. $footer = "";
  252. }
  253. if(!empty( $extra )) {
  254. $extrafields = explode("&", $extra);
  255. array_shift($extrafields);
  256. foreach( $extrafields as $key => $value) {
  257. $field = explode("=", $value);
  258. $footer .= '<input type="hidden" name="'.$field[0].'" value="'.@shopMakeHtmlSafe($field[1]).'" />'."\n";
  259. }
  260. }
  261. $footer .= '</form>';
  262. echo $footer;
  263. }
  264. }
  265. /**
  266. * This is the class for creating regular forms used in VirtueMart
  267. *
  268. * Usage:
  269. * //First create the object and let it print a form heading
  270. * $formObj = &new formFactory( "My Form" );
  271. * //Then Start the form
  272. * $formObj->startForm();
  273. * // Add necessary hidden fields
  274. * $formObj->hiddenField( 'country_id', $country_id );
  275. *
  276. * // Write your form with mixed tags and text fields
  277. * // and finally close the form:
  278. * $formObj->finishForm( $funcname, $modulename.'.country_list' );
  279. *
  280. * @package virtuemart
  281. * @subpackage Core
  282. * @author soeren
  283. */
  284. class formFactory {
  285. /**
  286. * Constructor
  287. * Prints the Form Heading if provided
  288. */
  289. function formFactory( $title = '' ) {
  290. if( $title != "" ) {
  291. echo '<div class="header"><h2 style="margin: 0px;">'.$title."</h2></div>\n";
  292. $GLOBALS['vm_mainframe']->setPageTitle( $title );
  293. }
  294. }
  295. /**
  296. * Writes the form start tag
  297. */
  298. function startForm( $formname = 'adminForm', $extra = "" ) {
  299. $action = (!defined('_VM_IS_BACKEND' ) && !empty($_REQUEST['next_page'])) ? 'index.php' : $_SERVER['PHP_SELF'];
  300. echo '<form method="post" action="'. $action .'" name="'.$formname.'" '.$extra.' target="_self">';
  301. }
  302. function hiddenField( $name, $value ) {
  303. echo ' <input type="hidden" name="'.$name.'" value="'.shopMakeHtmlSafe($value).'" />
  304. ';
  305. }
  306. /**
  307. * Writes necessary hidden input fields
  308. * and closes the form
  309. */
  310. function finishForm( $func, $page='' ) {
  311. $no_menu = vmRequest::getInt('no_menu');
  312. $html = '
  313. <input type="hidden" name="vmtoken" value="'.vmSpoofValue($GLOBALS['sess']->getSessionId()).'" />
  314. <input type="hidden" name="func" value="'.$func.'" />
  315. <input type="hidden" name="page" value="'.$page.'" />
  316. <input type="hidden" name="task" value="" />
  317. <input type="hidden" name="option" value="'.VM_COMPONENT_NAME.'" />';
  318. if( $no_menu ) {
  319. $html .= '<input type="hidden" name="ajax_request" value="1" />';
  320. }
  321. $html .= '<input type="hidden" name="no_menu" value="'.$no_menu.'" />';
  322. $html .= '<input type="hidden" name="no_toolbar" value="'.vmGet($_REQUEST,'no_toolbar',0).'" />';
  323. $html .= '<input type="hidden" name="only_page" value="'.vmGet($_REQUEST,'only_page',0).'" />';
  324. if( defined( "_VM_IS_BACKEND") || @$_REQUEST['pshop_mode'] == "admin" ) {
  325. $html .= '<input type="hidden" name="pshop_admin" value="admin" />';
  326. }
  327. $html .= '
  328. </form>
  329. ';
  330. echo $html;
  331. }
  332. }
  333. /**
  334. * Tab Creation handler
  335. * @package VirtueMart
  336. * @subpackage core
  337. * @author soeren
  338. * Modified to use Panel-in-Panel functionality
  339. */
  340. class vmTabPanel {
  341. /** @var int Use cookies */
  342. var $useCookies = 0;
  343. /** @var string Panel ID */
  344. var $panel_id;
  345. var $tabs;
  346. /**
  347. * Constructor
  348. * Includes files needed for displaying tabs and sets cookie options
  349. * @param int useCookies, if set to 1 cookie will hold last used tab between page refreshes
  350. * @param int show_js, if set to 1 the Javascript Link and Stylesheet will not be printed
  351. */
  352. function vmTabPanel($useCookies, $show_js, $panel_id) {
  353. vmCommonHTML::loadExtjs();
  354. $this->useCookies = $useCookies;
  355. $this->panel_id = $panel_id;
  356. $this->tabs = array();
  357. }
  358. /**
  359. * creates a tab pane and creates JS obj
  360. * @param string The Tab Pane Name
  361. */
  362. function startPane($id) {
  363. echo "<div class=\"tab-page\" id=\"".$id."\">";
  364. $this->pane_id = $id;
  365. }
  366. /**
  367. * Ends Tab Pane
  368. */
  369. function endPane() {
  370. echo "</div>";
  371. $scripttag = "
  372. Ext.onReady( function() {
  373. Ext.QuickTips.init();
  374. var state = Ext.state.Manager;
  375. var tabs_{$this->panel_id} = new Ext.TabPanel({
  376. renderTo: '{$this->pane_id}',
  377. activeTab: 0,
  378. deferredRender: false,
  379. items: [";
  380. $num = 0;
  381. $numTabs = count( $this->tabs );
  382. foreach ( $this->tabs as $id => $title ) {
  383. $scripttag .= "{ contentEl: '$id', title: '".addslashes($title)."' , tabTip: '".addslashes(strip_tags($title))."' }";
  384. $num++;
  385. if( $num < $numTabs ) {
  386. $scripttag .= ",\n";
  387. }
  388. }
  389. $scripttag .= "]
  390. });";
  391. reset($this->tabs);
  392. if( $this->useCookies ) {
  393. $scripttag .= "tabs_{$this->panel_id}.activate(state.get('{$this->panel_id}-active', '".key($this->tabs)."'));";
  394. } else {
  395. $scripttag .= "tabs_{$this->panel_id}.activate( '".key($this->tabs)."'); ";
  396. }
  397. if( $this->useCookies ) {
  398. $scripttag .= "
  399. Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
  400. tabs_{$this->panel_id}.on('tabchange', function(tp, tab){
  401. state.set('{$this->panel_id}-active', tab.id);
  402. });
  403. ";
  404. }
  405. $scripttag .= "});";
  406. echo vmCommonHTML::scriptTag('', $scripttag );
  407. }
  408. /*
  409. * Creates a tab with title text and starts that tabs page
  410. * @param tabText - This is what is displayed on the tab
  411. * @param paneid - This is the parent pane to build this tab on
  412. */
  413. function startTab( $tabText, $paneid ) {
  414. echo "<div class=\"tab-page\" id=\"".$paneid."\">";
  415. $this->tabs[$paneid] = $tabText;
  416. }
  417. /*
  418. * Ends a tab page
  419. */
  420. function endTab() {
  421. echo "</div>";
  422. }
  423. }
  424. class mShopTabs extends vmTabPanel { }
  425. class vmMooAjax {
  426. /**
  427. * This is used to print out Javascript code for the moo.ajax script
  428. *
  429. * @param string $url
  430. * @param string $updateId
  431. * @param string $onComplete A JS function name to be called after the HTTP transport has been finished
  432. * @param array VM_COMPONENT_NAMEs
  433. * @param string $varName The name of a variable the ajax object is assigned to
  434. */
  435. function writeAjaxUpdater( $url, $updateId, $onComplete, $method='post', $vmDirs=array(), $varName='' ) {
  436. echo vmMooAjax::getAjaxUpdater($url, $updateId, $onComplete, $methods, $vmDirs, $varName);
  437. }
  438. function getAjaxUpdater( $url, $updateId, $onComplete, $method='post', $vmDirs=array(), $varName='' ) {
  439. global $mosConfig_live_site;
  440. vmCommonHTML::loadMooTools();
  441. $path = defined('_VM_IS_BACKEND' ) ? '/administrator/' : '/';
  442. $vmDirs['method'] = $method;
  443. $html = '';
  444. if( $varName ) {
  445. $html .= 'var '.$varName.' = ';
  446. }
  447. if( !strstr( $url, $mosConfig_live_site) && !strstr($url, 'http' )) {
  448. $url = $mosConfig_live_site.$path.$url;
  449. }
  450. $html .= "new ajax('$url', {\n";
  451. foreach (VM_COMPONENT_NAMEs as $key => $val) {
  452. if( strstr( $val, '.')) {
  453. $html .= "$key: $val,\n";
  454. }
  455. else {
  456. $html .= "$key: '$val',\n";
  457. }
  458. }
  459. if( $updateId != '' ) {
  460. $html .= "update: '$updateId'";
  461. if( $onComplete ) { $html .= ",\n"; }
  462. }
  463. if( $onComplete ) {
  464. $html .= "onComplete: $onComplete";
  465. }
  466. $html .= '
  467. });';
  468. return $html;
  469. }
  470. }
  471. /**
  472. * This is the class offering functions for common HTML tasks
  473. *
  474. */
  475. class vmCommonHTML {
  476. /**
  477. * function to create a hyperlink
  478. *
  479. * @param string $link
  480. * @param string $text
  481. * @param string $target
  482. * @param string $title
  483. * @param string $attributes
  484. * @return string
  485. */
  486. function hyperLink( $link, $text, $target='', $title='', $attributes='' ) {
  487. if( $target ) {
  488. $target = ' target="'.$target.'"';
  489. }
  490. if( $title ) {
  491. $title = ' title="'.$title.'"';
  492. }
  493. if( $attributes ) {
  494. $attributes = ' ' . $attributes;
  495. }
  496. return '<a href="'.vmAmpReplace($link).'"'.$target.$title.$attributes.'>'.$text.'</a>';
  497. }
  498. /**
  499. * Function to create an image tag
  500. *
  501. * @param string $src
  502. * @param string $alt
  503. * @param int $height
  504. * @param int $width
  505. * @param string $title
  506. * @param int $border
  507. * @param string $attributes
  508. * @return string
  509. */
  510. function imageTag( $src, $alt='', $align='', $height='', $width='', $title='', $border='0', $attributes='' ) {
  511. if( $align ) { $align = ' align="'.$align.'"'; }
  512. if( $height ) { $height = ' height="'.$height.'"'; }
  513. if( $width ) { $width = ' width="'.$width.'"'; }
  514. if( $title ) { $title = ' title="'.$title.'"'; }
  515. if( $attributes ) { $attributes = ' ' . $attributes; }
  516. if( strpos($attributes, 'border=')===false) {
  517. $border = ' border="'.$border.'"';
  518. } // Prevent doubled attributes
  519. if( strpos($attributes, 'alt=')===false) {
  520. $alt = ' alt="'.$alt.'"';
  521. }
  522. return '<img src="'.$src.'"'.$alt.$align.$title.$height.$width.$border.$attributes.' />';
  523. }
  524. /**
  525. * Returns a properly formatted XHTML List
  526. *
  527. * @param array $listitems
  528. * @param string $type Can be ul, ol, ...
  529. * @param string $style
  530. * @return string
  531. */
  532. function getList( $listitems, $type = 'ul', $style='' ) {
  533. if( $style ) {
  534. $style = 'style="'.$style.'"';
  535. }
  536. $html = '<' . $type ." $style>\n";
  537. foreach( $listitems as $item ) {
  538. $html .= '<li>' . $item . "</li>\n";
  539. }
  540. $html .= '</' . $type .">\n";
  541. return $html;
  542. }
  543. /**
  544. * Returns a script tag. The referenced script will be fetched by a
  545. * PHP script called "fetchscript.php"
  546. * That allows use gzip compression, so bigger Javascripts don't steal our bandwith
  547. *
  548. * @param string $src The script src reference
  549. * @param string $content A Javascript Text to include in a script tag
  550. * @return string
  551. */
  552. function scriptTag( $src='', $content = '' ) {
  553. global $mosConfig_gzip, $mosConfig_live_site;
  554. if( $src == '' && $content == '' ) return;
  555. if( $src ) {
  556. if( isset( $_REQUEST['usefetchscript'])) {
  557. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1 );
  558. vmRequest::setVar( 'usefetchscript', $use_fetchscript, 'session' );
  559. } else {
  560. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1, 'session' );
  561. }
  562. $urlpos = strpos( $src, '?' );
  563. $url_params = '';
  564. if( $urlpos ) {
  565. $url_params = '&amp;'.substr( $src, $urlpos );
  566. $src = substr( $src, 0, $urlpos);
  567. }
  568. if( stristr( $src, 'com_virtuemart' ) && !stristr( $src, '.php' ) && $use_fetchscript ) {
  569. $base_source = str_replace( URL, '', $src );
  570. $base_source = str_replace( SECUREURL, '', $base_source );
  571. $base_source = str_replace( '/components/com_virtuemart', '', $base_source);
  572. $base_source = str_replace( 'components/com_virtuemart', '', $base_source);
  573. $src = $mosConfig_live_site.'/components/com_virtuemart/fetchscript.php?gzip='.$mosConfig_gzip.'&amp;subdir[0]='.dirname( $base_source ) . '&amp;file[0]=' . basename( $src );
  574. }
  575. return '<script src="'.$src.@$url_params.'" type="text/javascript"></script>'."\n";
  576. }
  577. if( $content ) {
  578. return "<script type=\"text/javascript\">\n".$content."\n</script>\n";
  579. }
  580. }
  581. /**
  582. * Returns a link tag
  583. *
  584. * @param string $href
  585. * @param string $type
  586. * @param string $rel
  587. * @return string
  588. */
  589. function linkTag( $href, $type='text/css', $rel = 'stylesheet', $media="screen, projection" ) {
  590. global $mosConfig_gzip, $mosConfig_live_site;
  591. if( isset( $_REQUEST['usefetchscript'])) {
  592. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1 );
  593. vmRequest::setVar( 'usefetchscript', $use_fetchscript, 'session' );
  594. } else {
  595. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1, 'session' );
  596. }
  597. if( stristr( $href, 'com_virtuemart' ) && $use_fetchscript) {
  598. $base_href = str_replace( URL, '', $href );
  599. $base_href = str_replace( SECUREURL, '', $base_href );
  600. $base_href = str_replace( 'components/com_virtuemart/', '', $base_href);
  601. $href = $mosConfig_live_site.'/components/com_virtuemart/fetchscript.php?gzip='.$mosConfig_gzip.'&amp;subdir[0]='.dirname( $base_href ) . '&amp;file[0]=' . basename( $href );
  602. }
  603. return '<link type="'.$type.'" href="'.$href.'" rel="'.$rel.'"'.(empty($media)?'':' media="'.$media.'"').' />'."\n";
  604. }
  605. /**
  606. * Writes a "Save Ordering" Button
  607. * @param int the number of rows
  608. */
  609. function getSaveOrderButton( $num_rows, $funcname='reorder') {
  610. global $mosConfig_live_site, $VM_LANG;
  611. $n = $num_rows-1;
  612. $html = '<a href="javascript: document.adminForm.func.value = \''.$funcname.'\'; saveorder( '.$n.' );">
  613. <img src="'.$mosConfig_live_site.'/administrator/images/filesave.png" border="0" width="16" height="16" alt="'.$VM_LANG->_('VM_SORT_SAVE_ORDER').'" /></a>';
  614. $html .= '<a href="javascript: if( confirm( \''.addslashes($VM_LANG->_('VM_SORT_ALPHA_CONFIRM')).'\')) { document.adminForm.func.value = \''.$funcname.'\'; document.adminForm.task.value=\'sort_alphabetically\'; document.adminForm.submit(); }">
  615. <img src="'.IMAGEURL.'/ps_image/sort_a-z.gif" border="0" width="16" height="16" alt="'.$VM_LANG->_('VM_SORT_ALPHA').'" /></a>';
  616. return $html;
  617. }
  618. function getOrderingField( $ordering ) {
  619. return '<input type="text" name="order[]" size="5" value="'. $ordering .'" class="text_area" style="text-align: center" />';
  620. }
  621. function getYesNoIcon( $condition, $pos_alt = "Published", $neg_alt = "Unpublished" ) {
  622. global $mosConfig_live_site;
  623. if( $condition===true || strtoupper( $condition ) == "Y" || $condition == '1' ) {
  624. return '<img src="'.$mosConfig_live_site.'/administrator/images/tick.png" border="0" alt="'.$pos_alt.'" />';
  625. }
  626. else {
  627. return '<img src="'.$mosConfig_live_site.'/administrator/images/publish_x.png" border="0" alt="'.$neg_alt.'" />';
  628. }
  629. }
  630. /**
  631. * @param int The row index
  632. * @param int The record id
  633. * @param boolean
  634. * @param string The name of the form element
  635. * @return string
  636. */
  637. function idBox( $rowNum, $recId, $checkedOut=false, $name='cid' ) {
  638. if ( $checkedOut ) {
  639. return '';
  640. } else {
  641. return '<input type="checkbox" id="cb'.$rowNum.'" name="'.$name.'[]" value="'.$recId.'" onclick="isChecked(this.checked);" />';
  642. }
  643. }
  644. /**
  645. * Manipulates an array and fills the $index with selected="selected"
  646. * Indexes within $disableArr will be filled with disabled="disabled"
  647. *
  648. * @param array $arr
  649. * @param int $index
  650. * @param string $att
  651. * @param array $disableArr
  652. */
  653. function setSelectedArray( &$arr, $index, $att='selected', $disableArr=array() ) {
  654. if( !isset($arr[$index])) {
  655. return;
  656. }
  657. foreach( $arr as $key => $val ) {
  658. $arr[$key] = '';
  659. if( $key == $index ) {
  660. $arr[$key] = $att.'="'.$att.'"';
  661. }
  662. elseif( in_array( $key, $disableArr )) {
  663. $arr[$key] = 'disabled="disabled"';
  664. }
  665. }
  666. }
  667. /**
  668. * tests for template/default pathway arrow separator
  669. * @author FTW Stroker
  670. * @static
  671. * @return string The separator for the pathway breadcrumbs
  672. */
  673. function pathway_separator() {
  674. global $vm_mainframe,$mainframe, $mosConfig_absolute_path, $mosConfig_live_site;
  675. $imgPath = 'templates/' . $mainframe->getTemplate() . '/images/arrow.png';
  676. if (file_exists( "$mosConfig_absolute_path/$imgPath" )){
  677. $img = '<img src="' . $mosConfig_live_site . '/' . $imgPath . '" border="0" alt="arrow" />';
  678. } else {
  679. $imgPath = '/images/M_images/arrow.png';
  680. if (file_exists( $mosConfig_absolute_path . $imgPath )){
  681. $img = '<img src="' . $mosConfig_live_site . '/images/M_images/arrow.png" alt="arrow" />';
  682. } else {
  683. $img = '&gt;';
  684. }
  685. }
  686. return $img;
  687. }
  688. /**
  689. * Function to include the MooTools JS scripts in the HTML document
  690. * http://mootools.net
  691. * @static
  692. * @since VirtueMart 1.1.0
  693. *
  694. */
  695. function loadMooTools( $version='' ) {
  696. global $mosConfig_live_site, $vm_mainframe, $VM_LANG;
  697. if( !defined( "_MOOTOOLS_LOADED" )) {
  698. if( $version == '' ) {
  699. $version = 'mootools-release-1.11.js';
  700. }
  701. $vm_mainframe->addScriptDeclaration( 'var cart_title = "'.$VM_LANG->_('PHPSHOP_CART_TITLE').'";var ok_lbl="'.$VM_LANG->_('CMN_CONTINUE').'";var cancel_lbl="'.$VM_LANG->_('CMN_CANCEL').'";var notice_lbl="'.$VM_LANG->_('PEAR_LOG_NOTICE').'";' );
  702. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/mootools/'.$version );
  703. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/mootools/mooPrompt.js' );
  704. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/mootools/mooPrompt.css' );
  705. define ( "_MOOTOOLS_LOADED", "1" );
  706. }
  707. }
  708. /**
  709. * Function to load the javascript and stylsheet files for Slimbox,
  710. * a Lightbox derivate with mootools and prototype.lite
  711. * @author http://www.digitalia.be/software/slimbox
  712. *
  713. * @param boolean $print
  714. */
  715. function loadSlimBox( ) {
  716. global $mosConfig_live_site, $vm_mainframe;
  717. if( !defined( '_SLIMBOX_LOADED' )) {
  718. vmCommonHTML::loadMooTools();
  719. $vm_mainframe->addScriptDeclaration( 'var slimboxurl = \''.$mosConfig_live_site.'/components/'. VM_COMPONENT_NAME .'/js/slimbox/\';');
  720. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/slimbox/js/slimbox.js' );
  721. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/slimbox/css/slimbox.css' );
  722. define ( '_SLIMBOX_LOADED', '1' );
  723. }
  724. }
  725. /**
  726. * Prototype is a Javascript framework
  727. * @author http://prototype.conio.net/
  728. *
  729. */
  730. function loadPrototype( ) {
  731. global $vm_mainframe, $mosConfig_live_site;
  732. if( !defined( "_PROTOTYPE_LOADED" )) {
  733. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/prototype/prototype.js' );
  734. define( '_PROTOTYPE_LOADED', 1 );
  735. }
  736. }
  737. /**
  738. * Loads the CSS and Javascripts needed to run the Greybox
  739. * Source: http://orangoo.com/labs/?page_id=5
  740. *
  741. */
  742. function loadGreybox( ) {
  743. global $mosConfig_live_site, $vm_mainframe;
  744. if( !defined( '_GREYBOX_LOADED' )) {
  745. $vm_mainframe->addScriptDeclaration( 'var GB_ROOT_DIR = \''.$mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/\';' );
  746. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/AJS.js' );
  747. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/AJS_fx.js' );
  748. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/gb_scripts.js' );
  749. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/gb_styles.css' );
  750. define ( '_GREYBOX_LOADED', '1' );
  751. }
  752. }
  753. /**
  754. * Loads all necessary script files for Tigra Tree Menu
  755. * @static
  756. * @since VirtueMart 1.1.0
  757. */
  758. function loadTigraTree( ) {
  759. global $mosConfig_live_site, $vm_mainframe;
  760. if( !defined( "_TIGRATREE_LOADED" )) {
  761. if( vmIsJoomla( '1.5' )) {
  762. $js_src = $mosConfig_live_site.'/modules/mod_virtuemart';
  763. } else {
  764. $js_src = $mosConfig_live_site.'/modules';
  765. }
  766. $vm_mainframe->addScript( $js_src .'/tigratree/tree_tpl.js.php' );
  767. $vm_mainframe->addScript( $js_src .'/tigratree/tree.js' );
  768. define ( "_TIGRATREE_LOADED", "1" );
  769. }
  770. }
  771. function loadYUI( ) {
  772. global $mosConfig_live_site, $vm_mainframe;
  773. if( !defined( "_YUI_LOADED" )) {
  774. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/yui-utilities.js' );
  775. define ( "_YUI_LOADED", "1" );
  776. }
  777. }
  778. function loadExtjs() {
  779. global $mosConfig_live_site, $vm_mainframe;
  780. vmCommonHTML::loadYUI();
  781. if( !defined( "_EXTJS_LOADED" )) {
  782. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/ext-yui-adapter.js' );
  783. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/ext-all.js' );
  784. $vm_mainframe->addScriptDeclaration( 'Ext.BLANK_IMAGE_URL = "'.$mosConfig_live_site.'/components/'. VM_COMPONENT_NAME .'/js/extjs2/images/default/s.gif";' );
  785. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/css/ext-all.css' );
  786. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/css/xtheme-gray.css' );
  787. define ( "_EXTJS_LOADED", "1" );
  788. }
  789. }
  790. /**
  791. * Returns a properly formatted image link that opens a LightBox2/Slimbox
  792. *
  793. * @param string $image_link Can be the image src or a complete image tag
  794. * @param string $text The Link Text, e.g. 'Click here!'
  795. * @param string $title The Link title, will be used as Image Caption
  796. * @param string $image_group The image group name when you want to use the gallery functionality
  797. * @param string $mootools Set to 'true' if you're using slimbox or another MooTools based image viewing library
  798. * @return string
  799. */
  800. function getLightboxImageLink( $image_link, $text, $title='', $image_group='' ) {
  801. vmCommonHTML::loadSlimBox();
  802. if( $image_group ) {
  803. $image_group = '['.$image_group.']';
  804. }
  805. $link = vmCommonHTML::hyperLink( $image_link, $text, '', $title, 'rel="lightbox'.$image_group.'"' );
  806. return $link;
  807. }
  808. function getGreyboxPopUpLink( $url, $text, $target='_blank', $title='', $attributes='', $height=500, $width=600, $no_js_url='' ) {
  809. vmCommonHTML::loadGreybox();
  810. if( $no_js_url == '') {
  811. $no_js_url = $url;
  812. }
  813. $link = vmCommonHTML::hyperLink( $no_js_url, $text, $target, $title, $attributes.' onclick="try{ if( !parent.GB ) return GB_showCenter(\''.$title.'\', \''.$url.'\', '.$height.', '.$width.');} catch(e) { }"' );
  814. return $link;
  815. }
  816. /**
  817. * Returns a div element of the class "shop_error"
  818. * containing $msg to print out an error
  819. *
  820. * @param string $msg
  821. * @return string HTML code
  822. */
  823. function getInfoField( $msg ) {
  824. $html = '<div class="shop_info">'.$msg.'</div>';
  825. return $html;
  826. }
  827. /**
  828. * Returns a div element to indicate success or failure of a function execution after an ajax call
  829. * and a div element with all the log messages
  830. *
  831. * @param boolean $success
  832. * @param vmLog_Display $vmLogger
  833. */
  834. function getSuccessIndicator( $success, $vmDisplayLogger ) { /*@MWM1*/
  835. echo '<div id="successIndicator" style="display:none;">';
  836. if( $success) {
  837. echo 'Success';
  838. }
  839. else {
  840. echo 'Failure';
  841. }
  842. echo '</div>';
  843. echo '<div id="vmLogResult">';
  844. $vmDisplayLogger->printLog(); /*@MWM1: Log/Debug enhancements*/
  845. echo '</div>';
  846. }
  847. /**
  848. * Returns a div element of the class "shop_error"
  849. * containing $msg to print out an error
  850. *
  851. * @param string $msg
  852. * @return string HTML code
  853. */
  854. function getErrorField( $msg ) {
  855. $html = '<div class="shop_error">'.$msg.'</div>';
  856. return $html;
  857. }
  858. /**
  859. * Writes a PDF icon
  860. *
  861. * @param string $link
  862. * @param boolean $use_icon
  863. */
  864. function PdfIcon( $link, $use_icon=true ) {
  865. global $VM_LANG, $mosConfig_live_site;
  866. if ( PSHOP_PDF_BUTTON_ENABLE == '1' && !vmGet( $_REQUEST, 'pop' ) ) {
  867. $link .= '&amp;pop=1';
  868. if ( $use_icon ) {
  869. $text = vmCommonHTML::ImageCheck( 'pdf_button.png', '/images/M_images/', NULL, NULL, $VM_LANG->_('CMN_PDF'), $VM_LANG->_('CMN_PDF') );
  870. } else {
  871. $text = $VM_LANG->_('CMN_PDF') .'&nbsp;';
  872. }
  873. return vmPopupLink($link, $text, 640, 480, '_blank', $VM_LANG->_('CMN_PDF'));
  874. }
  875. }
  876. /**
  877. * Writes an Email icon
  878. *
  879. * @param string $link
  880. * @param boolean $use_icon
  881. */
  882. function EmailIcon( $product_id, $use_icon=true ) {
  883. global $VM_LANG, $mosConfig_live_site, $sess;
  884. if ( @VM_SHOW_EMAILFRIEND == '1' && !vmGet( $_REQUEST, 'pop' ) && $product_id > 0 ) {
  885. $link = $sess->url( 'index2.php?page=shop.recommend&amp;product_id='.$product_id.'&amp;pop=1' );
  886. if ( $use_icon ) {
  887. $text = vmCommonHTML::ImageCheck( 'emailButton.png', '/images/M_images/', NULL, NULL, $VM_LANG->_('CMN_EMAIL'), $VM_LANG->_('CMN_EMAIL') );
  888. } else {
  889. $text = '&nbsp;'. $VM_LANG->_('CMN_EMAIL');
  890. }
  891. return vmPopupLink($link, $text, 640, 480, '_blank', $VM_LANG->_('CMN_EMAIL'), 'screenX=100,screenY=200');
  892. }
  893. }
  894. function PrintIcon( $link='', $use_icon=true, $add_text='' ) {
  895. global $VM_LANG, $mosConfig_live_site, $mosConfig_absolute_path, $cur_template, $Itemid;
  896. if ( @VM_SHOW_PRINTICON == '1' ) {
  897. if( !$link ) {
  898. $query_string = str_replace( 'only_page=1', 'only_page=0', vmAmpReplace(vmGet($_SERVER,'QUERY_STRING')) );
  899. $link = 'index2.php?'.$query_string.'&amp;pop=1';
  900. }
  901. // checks template image directory for image, if non found default are loaded
  902. if ( $use_icon ) {
  903. $text = vmCommonHTML::ImageCheck( 'printButton.png', '/images/M_images/', NULL, NULL, $VM_LANG->_('CMN_PRINT'), $VM_LANG->_('CMN_PRINT') );
  904. $text .= shopMakeHtmlSafe($add_text);
  905. } else {
  906. $text = '|&nbsp;'. $VM_LANG->_('CMN_PRINT'). '&nbsp;|';
  907. }
  908. $isPopup = vmGet( $_GET, 'pop' );
  909. if ( $isPopup ) {
  910. // Print Preview button - used when viewing page
  911. $html = '<span class="vmNoPrint">
  912. <a href="javascript:void(0)" onclick="javascript:window.print(); return false;" title="'. $VM_LANG->_('CMN_PRINT').'">
  913. '. $text .'
  914. </a></span>';
  915. return $html;
  916. } else {
  917. // Print Button - used in pop-up window
  918. return vmPopupLink($link, $text, 640, 480, '_blank', $VM_LANG->_('CMN_PRINT'));
  919. }
  920. }
  921. }
  922. /**
  923. * Checks to see if an image exists in the current templates image directory
  924. * if it does it loads this image. Otherwise the default image is loaded.
  925. * Also can be used in conjunction with the menulist param to create the chosen image
  926. * load the default or use no image
  927. */
  928. function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name=NULL, $type=1, $align='middle', $title=NULL, $admin=NULL ) {
  929. global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe;
  930. $cur_template = $mainframe->getTemplate();
  931. $name = ( $name ? ' name="'. $name .'"' : '' );
  932. $title = ( $title ? ' title="'. $title .'"' : '' );
  933. $alt = ( $alt ? ' alt="'. $alt .'"' : ' alt=""' );
  934. $align = ( $align ? ' align="'. $align .'"' : '' );
  935. // change directory path from frontend or backend
  936. if ($admin) {
  937. $path = '/administrator/templates/'. $cur_template .'/images/';
  938. } else {
  939. $path = '/templates/'. $cur_template .'/images/';
  940. }
  941. if ( $param ) {
  942. $image = $mosConfig_live_site. $param_directory . $param;
  943. if ( $type ) {
  944. $image = '<img src="'. $image .'" '. $alt . $name . $align .' border="0" />';
  945. }
  946. } else if ( $param == -1 ) {
  947. $image = '';
  948. } else {
  949. if ( file_exists( $mosConfig_absolute_path . $path . $file ) ) {
  950. $image = $mosConfig_live_site . $path . $file;
  951. } else {
  952. // outputs only path to image
  953. $image = $mosConfig_live_site. $directory . $file;
  954. }
  955. // outputs actual html <img> tag
  956. if ( $type ) {
  957. $image = '<img src="'. $image .'" '. $alt . $name . $title . $align .' border="0" />';
  958. }
  959. }
  960. return $image;
  961. }
  962. /**
  963. * this function parses all the text through all content plugins
  964. *
  965. * @param string $text
  966. * @param string $type
  967. */
  968. function ParseContentByPlugins( $text, $type = 'content' ) {
  969. global $_MAMBOTS;
  970. if( VM_CONTENT_PLUGINS_ENABLE == '1') {
  971. if( vmIsJoomla('1.0')) {
  972. $_MAMBOTS->loadBotGroup( $type );
  973. $row = new stdClass();
  974. $row->text = $text;
  975. $params = new mosParameters('');
  976. $_MAMBOTS->trigger( 'onPrepareContent', array( &$row, &$params, 0 ), true );
  977. $text = $row->text;
  978. } elseif( vmIsJoomla('1.5')) {
  979. $params =& $GLOBALS['mainframe']->getParams('com_content');
  980. $dispatcher =& JDispatcher::getInstance();
  981. JPluginHelper::importPlugin($type);
  982. $row = new stdClass();
  983. $row->text = $text;
  984. $results = $dispatcher->trigger('onPrepareContent', array (&$row, & $params, 0 ));
  985. $text = $row->text;
  986. }
  987. }
  988. return $text;
  989. }
  990. /**
  991. * This class allows us to create fieldsets like in Community builder
  992. * @author Copyright 2004 - 2005 MamboJoe/JoomlaJoe, Beat and CB team
  993. *
  994. * @param array $arr
  995. * @param string $tag_name
  996. * @param string $tag_attribs
  997. * @param string $key
  998. * @param string $text
  999. * @param mixed $selected
  1000. * @param mixed $required
  1001. * @return string HTML form code
  1002. */
  1003. // begin class vmCommonHTML extends mosHTML {
  1004. function radioListArr( &$arr, $tag_name, $tag_attribs, $key, $text, $selected, $required=0 ) {
  1005. reset( $arr );
  1006. $html = array();
  1007. $n=count( $arr );
  1008. for ($i=0; $i < $n; $i++ ) {
  1009. $k = stripslashes($arr[$i]->$key);
  1010. $t = stripslashes($arr[$i]->$text);
  1011. $id = isset($arr[$i]->id) ? $arr[$i]->id : null;
  1012. $extra = '';
  1013. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1014. if (is_array( $selected )) {
  1015. foreach ($selected as $obj) {
  1016. $k2 = stripslashes($obj->$key);
  1017. if ($k == $k2) {
  1018. $extra .= " checked=\"checked\"";
  1019. break;
  1020. }
  1021. }
  1022. } else {
  1023. $extra .= ($k == stripslashes($selected) ? " checked=\"checked\"" : '');
  1024. }
  1025. $html[] = "<input type=\"radio\" name=\"$tag_name\" id=\"".$tag_name."_field$i\" $tag_attribs value=\"".$k."\"$extra /> " . "<label for=\"".$tag_name."_field$i\">$t</label>";
  1026. }
  1027. return $html;
  1028. }
  1029. function radioList( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required=0 ) {
  1030. return "\n\t".implode("\n\t ", vmCommonHTML::radioListArr( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required ))."\n";
  1031. }
  1032. function radioListTable( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $cols=0, $rows=1, $size=0, $required=0 ) {
  1033. $cellsHtml = vmCommonHTML::radioListArr( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required );
  1034. return vmCommonHTML::list2Table( $cellsHtml, $cols, $rows, $size );
  1035. }
  1036. /**
  1037. * Writes a yes/no radio list
  1038. * @param string The value of the HTML name attribute
  1039. * @param string Additional HTML attributes for the <select> tag
  1040. * @param mixed The key that is selected
  1041. * @returns string HTML for the radio list
  1042. */
  1043. function yesnoRadioList( $tag_name, $tag_attribs, $key, $text, $selected, $yes='', $no='' ) {
  1044. global $VM_LANG;
  1045. $yes = ( $yes=='' ) ? $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES') : $yes;
  1046. $no = ( $no=='' ) ? $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO') : $no;
  1047. $arr = array(
  1048. vmCommonHTML::makeOption( '0', $no ),
  1049. vmCommonHTML::makeOption( '1', $yes )
  1050. );
  1051. return vmCommonHTML::radioList( $arr, $tag_name, $tag_attribs, $key, $text, $selected );
  1052. }
  1053. function makeOption( $value, $text='', $value_name='value', $text_name='text' ) {
  1054. $obj = new stdClass;
  1055. $obj->$value_name = $value;
  1056. $obj->$text_name = trim( $text ) ? $text : $value;
  1057. return $obj;
  1058. }
  1059. function selectList( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required=0 ) {
  1060. global $VM_LANG;
  1061. $t='';
  1062. reset( $arr );
  1063. $html = "\n<select name=\"$tag_name\" id=\"".str_replace('[]', '', $tag_name)."\" $tag_attribs>";
  1064. if(!$required) $html .= "\n\t<option value=\"\">".$VM_LANG->_('PHPSHOP_SELECT')."</option>";
  1065. $n=count( $arr );
  1066. for ($i=0; $i < $n; $i++ ) {
  1067. $k = stripslashes($arr[$i]->$key);
  1068. $t = stripslashes($arr[$i]->$text);
  1069. $id = isset($arr[$i]->id) ? $arr[$i]->id : null;
  1070. $extra = '';
  1071. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1072. if (is_array( $selected )) {
  1073. foreach ($selected as $obj) {
  1074. $k2 = stripslashes($obj->$key);
  1075. if ($k == $k2) {
  1076. $extra .= " selected=\"selected\"";
  1077. break;
  1078. }
  1079. }
  1080. } else {
  1081. $extra .= ($k == stripslashes($selected) ? " selected=\"selected\"" : '');
  1082. }
  1083. $html .= "\n\t<option value=\"".$k."\"$extra>";
  1084. //if(isset($t) && $t{0} == '_' && strlen($t)>0) $t = substr( $t, 1 );
  1085. $html .= isset($t) && $VM_LANG->exists($t) ? $VM_LANG->_($t) : $t;
  1086. $html .= "</option>";
  1087. }
  1088. $html .= "\n</select>\n";
  1089. return $html;
  1090. }
  1091. function checkboxListArr( $arr, $tag_name, $tag_attribs, $key='value', $text='text',$selected=null, $required=0 ) {
  1092. global $VM_LANG;
  1093. reset( $arr );
  1094. $html = array();
  1095. $n=count( $arr );
  1096. for ($i=0; $i < $n; $i++ ) {
  1097. $k = $arr[$i]->$key;
  1098. $t = $arr[$i]->$text;
  1099. $id = isset($arr[$i]->id) ? $arr[$i]->id : null;
  1100. $extra = '';
  1101. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1102. if (is_array( $selected )) {
  1103. foreach ($selected as $obj) {
  1104. $k2 = $obj->$key;
  1105. if ($k == $k2) {
  1106. $extra .= " checked=\"checked\"";
  1107. break;
  1108. }
  1109. }
  1110. } else {
  1111. $extra .= ($k == $selected ? " checked=\"checked\"" : '');
  1112. }
  1113. $tmp = "<input type=\"checkbox\" name=\"$tag_name\" id=\"".str_replace('[]', '', $tag_name)."_field$i\" value=\"".$k."\"$extra $tag_attribs />" . "<label for=\"".str_replace('[]', '', $tag_name)."_field$i\">";
  1114. $tmp .= $VM_LANG->exists($t) ? $VM_LANG->_($t) : $t;
  1115. $tmp .= "</label>";
  1116. $html[] = $tmp;
  1117. }
  1118. return $html;
  1119. }
  1120. function checkboxList( $arr, $tag_name, $tag_attribs, $key='value', $text='text',$selected=null, $required=0 ) {
  1121. return "\n\t".implode("\n\t", vmCommonHTML::checkboxListArr( $arr, $tag_name, $tag_attribs, $key, $text,$selected, $required ))."\n";
  1122. }
  1123. function checkboxListTable( $arr, $tag_name, $tag_attribs, $key='value', $text='text',$selected=null, $cols=0, $rows=0, $size=0, $required=0 ) {
  1124. $cellsHtml = vmCommonHTML::checkboxListArr( $arr, $tag_name, $tag_attribs, $key, $text,$selected, $required );
  1125. return vmCommonHTML::list2Table( $cellsHtml, $cols, $rows, $size );
  1126. }
  1127. // private methods:
  1128. function list2Table ( $cellsHtml, $cols, $rows, $size ) {
  1129. $cells = count($cellsHtml);
  1130. if ($size == 0) {
  1131. $localstyle = ""; //" style='width:100%'";
  1132. } else {
  1133. $size = (($size-($size % 3)) / 3 ) * 2; // int div 3 * 2 width/heigh ratio
  1134. $localstyle = " style='width:".$size."em;'";
  1135. }
  1136. $return="";
  1137. if ($cells) {
  1138. if ($rows) {
  1139. $return = "\n\t<table class='vmMulti'".$localstyle.">";
  1140. $cols = ($cells-($cells % $rows)) / $rows; // int div
  1141. if ($cells % $rows) $cols++;
  1142. $lineIdx=0;
  1143. for ($lineIdx=0 ; $lineIdx < min($rows, $cells) ; $lineIdx++) {
  1144. $return .= "\n\t\t<tr>";
  1145. for ($i=$lineIdx ; $i < $cells; $i += $rows) {
  1146. $return .= "<td>".$cellsHtml[$i]."</td>";
  1147. }
  1148. $return .= "</tr>\n";
  1149. }
  1150. $return .= "\t</table>\n";
  1151. } else if ($cols) {
  1152. $return = "\n\t<table class='vmMulti'".$localstyle.">";
  1153. $idx=0;
  1154. while ($cells) {
  1155. $return .= "\n\t\t<tr>";
  1156. for ($i=0, $n=min($cells,$cols); $i < $n; $i++, $cells-- ) {
  1157. $return .= "<td>".$cellsHtml[$idx++]."</td>";
  1158. }
  1159. $return .= "</tr>\n";
  1160. }
  1161. $return .= "\t</table>\n";
  1162. } else {
  1163. $return = "\n\t".implode("\n\t ", $cellsHtml)."\n";
  1164. }
  1165. }
  1166. return $return;
  1167. }
  1168. // end class vmCommonHTML, thanks folks!
  1169. }
  1170. /**
  1171. * Utility function to provide ToolTips
  1172. *
  1173. * @param string $tooltip ToolTip text
  1174. * @param string $title The Box title
  1175. * @param string $image
  1176. * @param int $width
  1177. * @param string $text
  1178. * @param string $href
  1179. * @param string $link
  1180. * @return string HTML code for ToolTip
  1181. */
  1182. function vmToolTip( $tooltip, $title='Tip!', $image = "{mosConfig_live_site}/images/M_images/con_info.png", $width='', $text='', $href='#', $link=false ) {
  1183. global $mosConfig_live_site, $database;
  1184. defined( 'vmToolTipCalled') or define('vmToolTipCalled', 1);
  1185. $tooltip = str_replace('"','&quot;',$tooltip);
  1186. $tooltip = $database->getEscaped($tooltip);
  1187. $tooltip = str_replace("&#039;","\&#039;",$tooltip);
  1188. if ( !empty($width) ) {
  1189. $width = 'this.T_WIDTH=\''.$width .'\';';
  1190. }
  1191. if ( $title ) {
  1192. $title = 'this.T_TITLE=\''.$title .'\';';
  1193. }
  1194. $image = str_replace( "{mosConfig_live_site}", $mosConfig_live_site, $image);
  1195. if( $image != '' ) {
  1196. $text = vmCommonHTML::imageTag( $image, '', 'absmiddle' ). '&nbsp;'.$text;
  1197. }
  1198. $style = 'style="text-decoration: none; color: #333;"';
  1199. if ( $href ) {
  1200. $style = '';
  1201. }
  1202. if ( $link ) {
  1203. $tip = vmCommonHTML::hyperLink( $href, $text, '','', "onmouseover=\"return escape( '$tooltip' );\" ". $style );
  1204. } else {
  1205. $tip = "<span onmouseover=\"$width $title return escape( '$tooltip' );\" ". $style .">". $text ."</span>";
  1206. }
  1207. return $tip;
  1208. }
  1209. /**
  1210. * @deprecated
  1211. */
  1212. function mm_ToolTip( $tooltip, $title='Tip!', $image = "{mosConfig_live_site}/images/M_images/con_info.png", $width='', $text='', $href='#', $link=false ) { return vmToolTip( $tooltip, $title, $image, $width, $text, $href, $link ); }
  1213. /**
  1214. * Utility function to provide persistant HelpToolTips
  1215. *
  1216. * @param unknown_type $tip
  1217. * @param unknown_type $linktext
  1218. */
  1219. function vmHelpToolTip( $tip, $linktext = ' [?] ' ) {
  1220. global $mosConfig_live_site;
  1221. if( !defined( 'vmHelpToolTipCalled')) {
  1222. echo '<script type="text/javascript" src="'.$mosConfig_live_site.'/components/com_virtuemart/js/helptip/helptip.js"></script>
  1223. <link type="text/css" rel="stylesheet" href="'.$mosConfig_live_site.'/components/com_virtuemart/js/helptip/helptip.css" />';
  1224. define('vmHelpToolTipCalled', 1);
  1225. }
  1226. $tip = str_replace( "\n", "",
  1227. str_replace( "&lt;", "<",
  1228. str_replace( "&gt;", ">",
  1229. str_replace( "&amp;", "&",
  1230. @htmlentities( $tip, ENT_QUOTES )))));
  1231. $varname = 'a'.md5( $tip );
  1232. echo '<script type="text/javascript">//<![CDATA[
  1233. var '.$varname.' = \''.$tip.'\';
  1234. //]]></script>
  1235. ';
  1236. echo '<a class="helpLink" href="?" onclick="showHelpTip(event, '.$varname.'); return false">'.$linktext.'</a>
  1237. ';
  1238. }
  1239. /**
  1240. * Converts all special chars to html entities
  1241. *
  1242. * @param string $string
  1243. * @param string $quote_style
  1244. * @param boolean $only_special_chars Only Convert Some Special Chars ? ( <, >, &, ... )
  1245. * @return string
  1246. */
  1247. function shopMakeHtmlSafe( $string, $quote_style='ENT_QUOTES', $use_entities=false ) {
  1248. if( defined( $quote_style )) {
  1249. $quote_style = constant($quote_style);
  1250. }
  1251. if( $use_entities ) {
  1252. $string = @htmlentities( $string, constant($quote_style), vmGetCharset() );
  1253. } else {
  1254. $string = @htmlspecialchars( $string, $quote_style, vmGetCharset() );
  1255. }
  1256. return $string;
  1257. }
  1258. function mm_showMyFileName( $filename ) {
  1259. if (vmShouldDebug()) { /*@MWM1: Logging/Debugging Enhancements */
  1260. echo vmToolTip( '<div class=\'inputbox\'>Begin of File: '. wordwrap( $filename, 70, '<br />', true ).'</div>');
  1261. }
  1262. }
  1263. /**
  1264. * Wraps HTML Code or simple Text into Javascript
  1265. * and uses the noscript Tag to support browsers with JavaScript disabled
  1266. **/
  1267. function mm_writeWithJS( $textToWrap, $noscriptText ) {
  1268. $text = "";
  1269. if( !empty( $textToWrap )) {
  1270. $text = "<script type=\"text/javascript\">//<![CDATA[
  1271. document.write('".str_replace("\\\"", "\"", addslashes( $textToWrap ))."');
  1272. //]]></script>\n";
  1273. }
  1274. if( !empty( $noscriptText )) {
  1275. $text .= "<noscript>
  1276. $noscriptText
  1277. </nosc

Large files files are truncated, but you can click here to view the full file