PageRenderTime 51ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 1457 lines | 1353 code | 10 blank | 94 comment | 15 complexity | 654108f8f550daa2273f02749308b9f2 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 1471 2008-07-14 18:35:42Z 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" enctype=multipart/form-data>';
  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. enableTabScroll: true,
  380. autoScroll: true,
  381. autoWidth: true,
  382. items: [";
  383. $num = 0;
  384. $numTabs = count( $this->tabs );
  385. foreach ( $this->tabs as $id => $title ) {
  386. $scripttag .= "{ autoHeight: true, contentEl: '$id', title: '".addslashes($title)."' , tabTip: '".addslashes(strip_tags($title))."' }";
  387. $num++;
  388. if( $num < $numTabs ) {
  389. $scripttag .= ",\n";
  390. }
  391. }
  392. $scripttag .= "]
  393. });";
  394. reset($this->tabs);
  395. if( $this->useCookies ) {
  396. $scripttag .= "tabs_{$this->panel_id}.activate(state.get('{$this->panel_id}-active', '".key($this->tabs)."'));";
  397. } else {
  398. $scripttag .= "tabs_{$this->panel_id}.activate( '".key($this->tabs)."'); ";
  399. }
  400. if( $this->useCookies ) {
  401. $scripttag .= "
  402. Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
  403. tabs_{$this->panel_id}.on('tabchange', function(tp, tab){
  404. state.set('{$this->panel_id}-active', tab.id);
  405. });
  406. ";
  407. }
  408. $scripttag .= "});";
  409. echo vmCommonHTML::scriptTag('', $scripttag );
  410. }
  411. /*
  412. * Creates a tab with title text and starts that tabs page
  413. * @param tabText - This is what is displayed on the tab
  414. * @param paneid - This is the parent pane to build this tab on
  415. */
  416. function startTab( $tabText, $paneid ) {
  417. echo "<div class=\"tab-page\" id=\"".$paneid."\">";
  418. $this->tabs[$paneid] = $tabText;
  419. }
  420. /*
  421. * Ends a tab page
  422. */
  423. function endTab() {
  424. echo "</div>";
  425. }
  426. }
  427. class mShopTabs extends vmTabPanel { }
  428. class vmMooAjax {
  429. /**
  430. * This is used to print out Javascript code for the moo.ajax script
  431. *
  432. * @param string $url
  433. * @param string $updateId
  434. * @param string $onComplete A JS function name to be called after the HTTP transport has been finished
  435. * @param array VM_COMPONENT_NAMEs
  436. * @param string $varName The name of a variable the ajax object is assigned to
  437. */
  438. function writeAjaxUpdater( $url, $updateId, $onComplete, $method='post', $vmDirs=array(), $varName='' ) {
  439. echo vmMooAjax::getAjaxUpdater($url, $updateId, $onComplete, $methods, $vmDirs, $varName);
  440. }
  441. function getAjaxUpdater( $url, $updateId, $onComplete, $method='post', $vmDirs=array(), $varName='' ) {
  442. global $mosConfig_live_site;
  443. vmCommonHTML::loadMooTools();
  444. $path = defined('_VM_IS_BACKEND' ) ? '/administrator/' : '/';
  445. $vmDirs['method'] = $method;
  446. $html = '';
  447. if( $varName ) {
  448. $html .= 'var '.$varName.' = ';
  449. }
  450. if( !strstr( $url, $mosConfig_live_site) && !strstr($url, 'http' )) {
  451. $url = $mosConfig_live_site.$path.$url;
  452. }
  453. $html .= "new ajax('$url', {\n";
  454. foreach (VM_COMPONENT_NAMEs as $key => $val) {
  455. if( strstr( $val, '.')) {
  456. $html .= "$key: $val,\n";
  457. }
  458. else {
  459. $html .= "$key: '$val',\n";
  460. }
  461. }
  462. if( $updateId != '' ) {
  463. $html .= "update: '$updateId'";
  464. if( $onComplete ) { $html .= ",\n"; }
  465. }
  466. if( $onComplete ) {
  467. $html .= "onComplete: $onComplete";
  468. }
  469. $html .= '
  470. });';
  471. return $html;
  472. }
  473. }
  474. /**
  475. * This is the class offering functions for common HTML tasks
  476. *
  477. */
  478. class vmCommonHTML {
  479. /**
  480. * function to create a hyperlink
  481. *
  482. * @param string $link
  483. * @param string $text
  484. * @param string $target
  485. * @param string $title
  486. * @param string $attributes
  487. * @return string
  488. */
  489. function hyperLink( $link, $text, $target='', $title='', $attributes='' ) {
  490. if( $target ) {
  491. $target = ' target="'.$target.'"';
  492. }
  493. if( $title ) {
  494. $title = ' title="'.$title.'"';
  495. }
  496. if( $attributes ) {
  497. $attributes = ' ' . $attributes;
  498. }
  499. return '<a href="'.vmAmpReplace($link).'"'.$target.$title.$attributes.'>'.$text.'</a>';
  500. }
  501. /**
  502. * Function to create an image tag
  503. *
  504. * @param string $src
  505. * @param string $alt
  506. * @param int $height
  507. * @param int $width
  508. * @param string $title
  509. * @param int $border
  510. * @param string $attributes
  511. * @return string
  512. */
  513. function imageTag( $src, $alt='', $align='', $height='', $width='', $title='', $border='0', $attributes='' ) {
  514. if( $align ) { $align = ' align="'.$align.'"'; }
  515. if( $height ) { $height = ' height="'.$height.'"'; }
  516. if( $width ) { $width = ' width="'.$width.'"'; }
  517. if( $title ) { $title = ' title="'.$title.'"'; }
  518. if( $attributes ) { $attributes = ' ' . $attributes; }
  519. if( strpos($attributes, 'border=')===false) {
  520. $border = ' border="'.$border.'"';
  521. } // Prevent doubled attributes
  522. if( strpos($attributes, 'alt=')===false) {
  523. $alt = ' alt="'.$alt.'"';
  524. }
  525. return '<img src="'.$src.'"'.$alt.$align.$title.$height.$width.$border.$attributes.' />';
  526. }
  527. /**
  528. * Returns a properly formatted XHTML List
  529. *
  530. * @param array $listitems
  531. * @param string $type Can be ul, ol, ...
  532. * @param string $style
  533. * @return string
  534. */
  535. function getList( $listitems, $type = 'ul', $style='' ) {
  536. if( $style ) {
  537. $style = 'style="'.$style.'"';
  538. }
  539. $html = '<' . $type ." $style>\n";
  540. foreach( $listitems as $item ) {
  541. $html .= '<li>' . $item . "</li>\n";
  542. }
  543. $html .= '</' . $type .">\n";
  544. return $html;
  545. }
  546. /**
  547. * Returns a script tag. The referenced script will be fetched by a
  548. * PHP script called "fetchscript.php"
  549. * That allows use gzip compression, so bigger Javascripts don't steal our bandwith
  550. *
  551. * @param string $src The script src reference
  552. * @param string $content A Javascript Text to include in a script tag
  553. * @return string
  554. */
  555. function scriptTag( $src='', $content = '' ) {
  556. global $mosConfig_gzip, $mosConfig_live_site;
  557. if( $src == '' && $content == '' ) return;
  558. if( $src ) {
  559. if( isset( $_REQUEST['usefetchscript'])) {
  560. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1 );
  561. vmRequest::setVar( 'usefetchscript', $use_fetchscript, 'session' );
  562. } else {
  563. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1, 'session' );
  564. }
  565. $urlpos = strpos( $src, '?' );
  566. $url_params = '';
  567. if( $urlpos ) {
  568. $url_params = '&amp;'.substr( $src, $urlpos );
  569. $src = substr( $src, 0, $urlpos);
  570. }
  571. if( stristr( $src, 'com_virtuemart' ) && !stristr( $src, '.php' ) && $use_fetchscript ) {
  572. $base_source = str_replace( URL, '', $src );
  573. $base_source = str_replace( SECUREURL, '', $base_source );
  574. $base_source = str_replace( '/components/com_virtuemart', '', $base_source);
  575. $base_source = str_replace( 'components/com_virtuemart', '', $base_source);
  576. $src = $mosConfig_live_site.'/components/com_virtuemart/fetchscript.php?gzip='.$mosConfig_gzip.'&amp;subdir[0]='.dirname( $base_source ) . '&amp;file[0]=' . basename( $src );
  577. }
  578. return '<script src="'.$src.@$url_params.'" type="text/javascript"></script>'."\n";
  579. }
  580. if( $content ) {
  581. return "<script type=\"text/javascript\">\n".$content."\n</script>\n";
  582. }
  583. }
  584. /**
  585. * Returns a link tag
  586. *
  587. * @param string $href
  588. * @param string $type
  589. * @param string $rel
  590. * @return string
  591. */
  592. function linkTag( $href, $type='text/css', $rel = 'stylesheet', $media="screen, projection" ) {
  593. global $mosConfig_gzip, $mosConfig_live_site;
  594. if( isset( $_REQUEST['usefetchscript'])) {
  595. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1 );
  596. vmRequest::setVar( 'usefetchscript', $use_fetchscript, 'session' );
  597. } else {
  598. $use_fetchscript = vmRequest::getBool( 'usefetchscript', 1, 'session' );
  599. }
  600. if( stristr( $href, 'com_virtuemart' ) && $use_fetchscript) {
  601. $base_href = str_replace( URL, '', $href );
  602. $base_href = str_replace( SECUREURL, '', $base_href );
  603. $base_href = str_replace( 'components/com_virtuemart/', '', $base_href);
  604. $href = $mosConfig_live_site.'/components/com_virtuemart/fetchscript.php?gzip='.$mosConfig_gzip.'&amp;subdir[0]='.dirname( $base_href ) . '&amp;file[0]=' . basename( $href );
  605. }
  606. return '<link type="'.$type.'" href="'.$href.'" rel="'.$rel.'"'.(empty($media)?'':' media="'.$media.'"').' />'."\n";
  607. }
  608. /**
  609. * Writes a "Save Ordering" Button
  610. * @param int the number of rows
  611. */
  612. function getSaveOrderButton( $num_rows, $funcname='reorder') {
  613. global $mosConfig_live_site, $VM_LANG;
  614. $n = $num_rows-1;
  615. $html = '<a href="javascript: document.adminForm.func.value = \''.$funcname.'\'; saveorder( '.$n.' );">
  616. <img src="'.$mosConfig_live_site.'/administrator/images/filesave.png" border="0" width="16" height="16" alt="'.$VM_LANG->_('VM_SORT_SAVE_ORDER').'" /></a>';
  617. $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(); }">
  618. <img src="'.IMAGEURL.'/ps_image/sort_a-z.gif" border="0" width="16" height="16" alt="'.$VM_LANG->_('VM_SORT_ALPHA').'" /></a>';
  619. return $html;
  620. }
  621. function getOrderingField( $ordering ) {
  622. return '<input type="text" name="order[]" size="5" value="'. $ordering .'" class="text_area" style="text-align: center" />';
  623. }
  624. function getYesNoIcon( $condition, $pos_alt = "Published", $neg_alt = "Unpublished" ) {
  625. global $mosConfig_live_site;
  626. if( $condition===true || strtoupper( $condition ) == "Y" || $condition == '1' ) {
  627. return '<img src="'.$mosConfig_live_site.'/administrator/images/tick.png" border="0" alt="'.$pos_alt.'" />';
  628. }
  629. else {
  630. return '<img src="'.$mosConfig_live_site.'/administrator/images/publish_x.png" border="0" alt="'.$neg_alt.'" />';
  631. }
  632. }
  633. /**
  634. * @param int The row index
  635. * @param int The record id
  636. * @param boolean
  637. * @param string The name of the form element
  638. * @return string
  639. */
  640. function idBox( $rowNum, $recId, $checkedOut=false, $name='cid' ) {
  641. if ( $checkedOut ) {
  642. return '';
  643. } else {
  644. return '<input type="checkbox" id="cb'.$rowNum.'" name="'.$name.'[]" value="'.$recId.'" onclick="isChecked(this.checked);" />';
  645. }
  646. }
  647. /**
  648. * Manipulates an array and fills the $index with selected="selected"
  649. * Indexes within $disableArr will be filled with disabled="disabled"
  650. *
  651. * @param array $arr
  652. * @param int $index
  653. * @param string $att
  654. * @param array $disableArr
  655. */
  656. function setSelectedArray( &$arr, $index, $att='selected', $disableArr=array() ) {
  657. if( !isset($arr[$index])) {
  658. return;
  659. }
  660. foreach( $arr as $key => $val ) {
  661. $arr[$key] = '';
  662. if( $key == $index ) {
  663. $arr[$key] = $att.'="'.$att.'"';
  664. }
  665. elseif( in_array( $key, $disableArr )) {
  666. $arr[$key] = 'disabled="disabled"';
  667. }
  668. }
  669. }
  670. /**
  671. * tests for template/default pathway arrow separator
  672. * @author FTW Stroker
  673. * @static
  674. * @return string The separator for the pathway breadcrumbs
  675. */
  676. function pathway_separator() {
  677. global $vm_mainframe,$mainframe, $mosConfig_absolute_path, $mosConfig_live_site;
  678. $imgPath = 'templates/' . $mainframe->getTemplate() . '/images/arrow.png';
  679. if (file_exists( "$mosConfig_absolute_path/$imgPath" )){
  680. $img = '<img src="' . $mosConfig_live_site . '/' . $imgPath . '" border="0" alt="arrow" />';
  681. } else {
  682. $imgPath = '/images/M_images/arrow.png';
  683. if (file_exists( $mosConfig_absolute_path . $imgPath )){
  684. $img = '<img src="' . $mosConfig_live_site . '/images/M_images/arrow.png" alt="arrow" />';
  685. } else {
  686. $img = '&gt;';
  687. }
  688. }
  689. return $img;
  690. }
  691. /**
  692. * Function to include the MooTools JS scripts in the HTML document
  693. * http://mootools.net
  694. * @static
  695. * @since VirtueMart 1.1.0
  696. *
  697. */
  698. function loadMooTools( $version='' ) {
  699. global $mosConfig_live_site, $vm_mainframe, $VM_LANG;
  700. if( !defined( "_MOOTOOLS_LOADED" )) {
  701. if( $version == '' ) {
  702. $version = 'mootools-release-1.11.js';
  703. }
  704. $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').'";var live_site="'.$mosConfig_live_site.'";' );
  705. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/mootools/'.$version );
  706. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/mootools/mooPrompt.js' );
  707. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/mootools/mooPrompt.css' );
  708. define ( "_MOOTOOLS_LOADED", "1" );
  709. }
  710. }
  711. /**
  712. * Function to load the javascript and stylsheet files for Slimbox,
  713. * a Lightbox derivate with mootools and prototype.lite
  714. * @author http://www.digitalia.be/software/slimbox
  715. *
  716. * @param boolean $print
  717. */
  718. function loadSlimBox( ) {
  719. global $mosConfig_live_site, $vm_mainframe;
  720. if( !defined( '_SLIMBOX_LOADED' )) {
  721. vmCommonHTML::loadMooTools();
  722. $vm_mainframe->addScriptDeclaration( 'var slimboxurl = \''.$mosConfig_live_site.'/components/'. VM_COMPONENT_NAME .'/js/slimbox/\';');
  723. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/slimbox/js/slimbox.js' );
  724. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/slimbox/css/slimbox.css' );
  725. define ( '_SLIMBOX_LOADED', '1' );
  726. }
  727. }
  728. /**
  729. * Prototype is a Javascript framework
  730. * @author http://prototype.conio.net/
  731. *
  732. */
  733. function loadPrototype( ) {
  734. global $vm_mainframe, $mosConfig_live_site;
  735. if( !defined( "_PROTOTYPE_LOADED" )) {
  736. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/prototype/prototype.js' );
  737. define( '_PROTOTYPE_LOADED', 1 );
  738. }
  739. }
  740. /**
  741. * Loads the CSS and Javascripts needed to run the Greybox
  742. * Source: http://orangoo.com/labs/?page_id=5
  743. *
  744. */
  745. function loadGreybox( ) {
  746. global $mosConfig_live_site, $vm_mainframe;
  747. if( !defined( '_GREYBOX_LOADED' )) {
  748. $vm_mainframe->addScriptDeclaration( 'var GB_ROOT_DIR = \''.$mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/\';' );
  749. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/AJS.js' );
  750. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/AJS_fx.js' );
  751. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/gb_scripts.js' );
  752. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/greybox/gb_styles.css' );
  753. define ( '_GREYBOX_LOADED', '1' );
  754. }
  755. }
  756. /**
  757. * Loads all necessary script files for Tigra Tree Menu
  758. * @static
  759. * @since VirtueMart 1.1.0
  760. */
  761. function loadTigraTree( ) {
  762. global $mosConfig_live_site, $vm_mainframe;
  763. if( !defined( "_TIGRATREE_LOADED" )) {
  764. if( vmIsJoomla( '1.5' )) {
  765. $js_src = $mosConfig_live_site.'/modules/mod_virtuemart';
  766. } else {
  767. $js_src = $mosConfig_live_site.'/modules';
  768. }
  769. $vm_mainframe->addScript( $js_src .'/tigratree/tree_tpl.js.php' );
  770. $vm_mainframe->addScript( $js_src .'/tigratree/tree.js' );
  771. define ( "_TIGRATREE_LOADED", "1" );
  772. }
  773. }
  774. function loadYUI( ) {
  775. global $mosConfig_live_site, $vm_mainframe;
  776. if( !defined( "_YUI_LOADED" )) {
  777. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/yui-utilities.js' );
  778. define ( "_YUI_LOADED", "1" );
  779. }
  780. }
  781. function loadExtjs() {
  782. global $mosConfig_live_site, $vm_mainframe;
  783. vmCommonHTML::loadYUI();
  784. if( !defined( "_EXTJS_LOADED" )) {
  785. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/ext-yui-adapter.js' );
  786. $vm_mainframe->addScript( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/ext-all.js' );
  787. $vm_mainframe->addScriptDeclaration( 'Ext.BLANK_IMAGE_URL = "'.$mosConfig_live_site.'/components/'. VM_COMPONENT_NAME .'/js/extjs2/images/default/s.gif";' );
  788. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/css/ext-all.css' );
  789. $vm_mainframe->addStyleSheet( $mosConfig_live_site .'/components/'. VM_COMPONENT_NAME .'/js/extjs2/css/xtheme-gray.css' );
  790. define ( "_EXTJS_LOADED", "1" );
  791. }
  792. }
  793. /**
  794. * Returns a properly formatted image link that opens a LightBox2/Slimbox
  795. *
  796. * @param string $image_link Can be the image src or a complete image tag
  797. * @param string $text The Link Text, e.g. 'Click here!'
  798. * @param string $title The Link title, will be used as Image Caption
  799. * @param string $image_group The image group name when you want to use the gallery functionality
  800. * @param string $mootools Set to 'true' if you're using slimbox or another MooTools based image viewing library
  801. * @return string
  802. */
  803. function getLightboxImageLink( $image_link, $text, $title='', $image_group='' ) {
  804. vmCommonHTML::loadSlimBox();
  805. if( $image_group ) {
  806. $image_group = '['.$image_group.']';
  807. }
  808. $link = vmCommonHTML::hyperLink( $image_link, $text, '', $title, 'rel="lightbox'.$image_group.'"' );
  809. return $link;
  810. }
  811. function getGreyboxPopUpLink( $url, $text, $target='_blank', $title='', $attributes='', $height=500, $width=600, $no_js_url='' ) {
  812. vmCommonHTML::loadGreybox();
  813. if( $no_js_url == '') {
  814. $no_js_url = $url;
  815. }
  816. $link = vmCommonHTML::hyperLink( $no_js_url, $text, $target, $title, $attributes.' onclick="try{ if( !parent.GB ) return GB_showCenter(\''.$title.'\', \''.$url.'\', '.$height.', '.$width.');} catch(e) { }"' );
  817. return $link;
  818. }
  819. /**
  820. * Returns a div element of the class "shop_error"
  821. * containing $msg to print out an error
  822. *
  823. * @param string $msg
  824. * @return string HTML code
  825. */
  826. function getInfoField( $msg ) {
  827. $html = '<div class="shop_info">'.$msg.'</div>';
  828. return $html;
  829. }
  830. /**
  831. * Returns a div element to indicate success or failure of a function execution after an ajax call
  832. * and a div element with all the log messages
  833. *
  834. * @param boolean $success
  835. * @param vmLog_Display $vmLogger
  836. */
  837. function getSuccessIndicator( $success, $vmDisplayLogger ) { /*@MWM1*/
  838. echo '<div id="successIndicator" style="display:none;">';
  839. if( $success) {
  840. echo 'Success';
  841. }
  842. else {
  843. echo 'Failure';
  844. }
  845. echo '</div>';
  846. echo '<div id="vmLogResult">';
  847. $vmDisplayLogger->printLog(); /*@MWM1: Log/Debug enhancements*/
  848. echo '</div>';
  849. }
  850. /**
  851. * Returns a div element of the class "shop_error"
  852. * containing $msg to print out an error
  853. *
  854. * @param string $msg
  855. * @return string HTML code
  856. */
  857. function getErrorField( $msg ) {
  858. $html = '<div class="shop_error">'.$msg.'</div>';
  859. return $html;
  860. }
  861. /**
  862. * Writes a PDF icon
  863. *
  864. * @param string $link
  865. * @param boolean $use_icon
  866. */
  867. function PdfIcon( $link, $use_icon=true ) {
  868. global $VM_LANG, $mosConfig_live_site;
  869. if ( PSHOP_PDF_BUTTON_ENABLE == '1' && !vmGet( $_REQUEST, 'pop' ) ) {
  870. $link .= '&amp;pop=1';
  871. if ( $use_icon ) {
  872. $text = vmCommonHTML::ImageCheck( 'pdf_button.png', '/images/M_images/', NULL, NULL, $VM_LANG->_('CMN_PDF'), $VM_LANG->_('CMN_PDF') );
  873. } else {
  874. $text = $VM_LANG->_('CMN_PDF') .'&nbsp;';
  875. }
  876. return vmPopupLink($link, $text, 640, 480, '_blank', $VM_LANG->_('CMN_PDF'));
  877. }
  878. }
  879. /**
  880. * Writes an Email icon
  881. *
  882. * @param string $link
  883. * @param boolean $use_icon
  884. */
  885. function EmailIcon( $product_id, $use_icon=true ) {
  886. global $VM_LANG, $mosConfig_live_site, $sess;
  887. if ( @VM_SHOW_EMAILFRIEND == '1' && !vmGet( $_REQUEST, 'pop' ) && $product_id > 0 ) {
  888. $link = $sess->url( 'index2.php?page=shop.recommend&amp;product_id='.$product_id.'&amp;pop=1'.(vmIsJoomla('1.5') ? '&amp;tmpl=component' : '') );
  889. if ( $use_icon ) {
  890. $text = vmCommonHTML::ImageCheck( 'emailButton.png', '/images/M_images/', NULL, NULL, $VM_LANG->_('CMN_EMAIL'), $VM_LANG->_('CMN_EMAIL') );
  891. } else {
  892. $text = '&nbsp;'. $VM_LANG->_('CMN_EMAIL');
  893. }
  894. return vmPopupLink($link, $text, 640, 480, '_blank', $VM_LANG->_('CMN_EMAIL'), 'screenX=100,screenY=200');
  895. }
  896. }
  897. function PrintIcon( $link='', $use_icon=true, $add_text='' ) {
  898. global $VM_LANG, $mosConfig_live_site, $mosConfig_absolute_path, $cur_template, $Itemid;
  899. if ( @VM_SHOW_PRINTICON == '1' ) {
  900. if( !$link ) {
  901. $query_string = str_replace( 'only_page=1', 'only_page=0', vmAmpReplace(vmGet($_SERVER,'QUERY_STRING')) );
  902. $link = 'index2.php?'.$query_string.'&amp;pop=1'.(vmIsJoomla('1.5') ? '&amp;tmpl=component' : '');
  903. }
  904. // checks template image directory for image, if non found default are loaded
  905. if ( $use_icon ) {
  906. $text = vmCommonHTML::ImageCheck( 'printButton.png', '/images/M_images/', NULL, NULL, $VM_LANG->_('CMN_PRINT'), $VM_LANG->_('CMN_PRINT') );
  907. $text .= shopMakeHtmlSafe($add_text);
  908. } else {
  909. $text = '|&nbsp;'. $VM_LANG->_('CMN_PRINT'). '&nbsp;|';
  910. }
  911. $isPopup = vmGet( $_GET, 'pop' );
  912. if ( $isPopup ) {
  913. // Print Preview button - used when viewing page
  914. $html = '<span class="vmNoPrint">
  915. <a href="javascript:void(0)" onclick="javascript:window.print(); return false;" title="'. $VM_LANG->_('CMN_PRINT').'">
  916. '. $text .'
  917. </a></span>';
  918. return $html;
  919. } else {
  920. // Print Button - used in pop-up window
  921. return vmPopupLink($link, $text, 640, 480, '_blank', $VM_LANG->_('CMN_PRINT'));
  922. }
  923. }
  924. }
  925. /**
  926. * Checks to see if an image exists in the current templates image directory
  927. * if it does it loads this image. Otherwise the default image is loaded.
  928. * Also can be used in conjunction with the menulist param to create the chosen image
  929. * load the default or use no image
  930. */
  931. 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 ) {
  932. global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe;
  933. $cur_template = $mainframe->getTemplate();
  934. $name = ( $name ? ' name="'. $name .'"' : '' );
  935. $title = ( $title ? ' title="'. $title .'"' : '' );
  936. $alt = ( $alt ? ' alt="'. $alt .'"' : ' alt=""' );
  937. $align = ( $align ? ' align="'. $align .'"' : '' );
  938. // change directory path from frontend or backend
  939. if ($admin) {
  940. $path = '/administrator/templates/'. $cur_template .'/images/';
  941. } else {
  942. $path = '/templates/'. $cur_template .'/images/';
  943. }
  944. if ( $param ) {
  945. $image = $mosConfig_live_site. $param_directory . $param;
  946. if ( $type ) {
  947. $image = '<img src="'. $image .'" '. $alt . $name . $align .' border="0" />';
  948. }
  949. } else if ( $param == -1 ) {
  950. $image = '';
  951. } else {
  952. if ( file_exists( $mosConfig_absolute_path . $path . $file ) ) {
  953. $image = $mosConfig_live_site . $path . $file;
  954. } else {
  955. // outputs only path to image
  956. $image = $mosConfig_live_site. $directory . $file;
  957. }
  958. // outputs actual html <img> tag
  959. if ( $type ) {
  960. $image = '<img src="'. $image .'" '. $alt . $name . $title . $align .' border="0" />';
  961. }
  962. }
  963. return $image;
  964. }
  965. /**
  966. * this function parses all the text through all content plugins
  967. *
  968. * @param string $text
  969. * @param string $type
  970. */
  971. function ParseContentByPlugins( $text, $type = 'content' ) {
  972. global $_MAMBOTS;
  973. if( VM_CONTENT_PLUGINS_ENABLE == '1') {
  974. if( vmIsJoomla('1.0')) {
  975. $_MAMBOTS->loadBotGroup( $type );
  976. $row = new stdClass();
  977. $row->text = $text;
  978. $params = new mosParameters('');
  979. $_MAMBOTS->trigger( 'onPrepareContent', array( &$row, &$params, 0 ), true );
  980. $text = $row->text;
  981. } elseif( vmIsJoomla('1.5')) {
  982. $params =& $GLOBALS['mainframe']->getParams('com_content');
  983. $dispatcher =& JDispatcher::getInstance();
  984. JPluginHelper::importPlugin($type);
  985. $row = new stdClass();
  986. $row->text = $text;
  987. $results = $dispatcher->trigger('onPrepareContent', array (&$row, & $params, 0 ));
  988. $text = $row->text;
  989. }
  990. }
  991. return $text;
  992. }
  993. /**
  994. * This class allows us to create fieldsets like in Community builder
  995. * @author Copyright 2004 - 2005 MamboJoe/JoomlaJoe, Beat and CB team
  996. *
  997. * @param array $arr
  998. * @param string $tag_name
  999. * @param string $tag_attribs
  1000. * @param string $key
  1001. * @param string $text
  1002. * @param mixed $selected
  1003. * @param mixed $required
  1004. * @return string HTML form code
  1005. */
  1006. // begin class vmCommonHTML extends mosHTML {
  1007. function radioListArr( &$arr, $tag_name, $tag_attribs, $key, $text, $selected, $required=0 ) {
  1008. reset( $arr );
  1009. $html = array();
  1010. $n=count( $arr );
  1011. for ($i=0; $i < $n; $i++ ) {
  1012. $k = stripslashes($arr[$i]->$key);
  1013. $t = stripslashes($arr[$i]->$text);
  1014. $id = isset($arr[$i]->id) ? $arr[$i]->id : null;
  1015. $extra = '';
  1016. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1017. if (is_array( $selected )) {
  1018. foreach ($selected as $obj) {
  1019. $k2 = stripslashes($obj->$key);
  1020. if ($k == $k2) {
  1021. $extra .= " checked=\"checked\"";
  1022. break;
  1023. }
  1024. }
  1025. } else {
  1026. $extra .= ($k == stripslashes($selected) ? " checked=\"checked\"" : '');
  1027. }
  1028. $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>";
  1029. }
  1030. return $html;
  1031. }
  1032. function radioList( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required=0 ) {
  1033. return "\n\t".implode("\n\t ", vmCommonHTML::radioListArr( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required ))."\n";
  1034. }
  1035. function radioListTable( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $cols=0, $rows=1, $size=0, $required=0 ) {
  1036. $cellsHtml = vmCommonHTML::radioListArr( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required );
  1037. return vmCommonHTML::list2Table( $cellsHtml, $cols, $rows, $size );
  1038. }
  1039. /**
  1040. * Writes a yes/no radio list
  1041. * @param string The value of the HTML name attribute
  1042. * @param string Additional HTML attributes for the <select> tag
  1043. * @param mixed The key that is selected
  1044. * @returns string HTML for the radio list
  1045. */
  1046. function yesnoRadioList( $tag_name, $tag_attribs, $key, $text, $selected, $yes='', $no='' ) {
  1047. global $VM_LANG;
  1048. $yes = ( $yes=='' ) ? $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES') : $yes;
  1049. $no = ( $no=='' ) ? $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO') : $no;
  1050. $arr = array(
  1051. vmCommonHTML::makeOption( '0', $no ),
  1052. vmCommonHTML::makeOption( '1', $yes )
  1053. );
  1054. return vmCommonHTML::radioList( $arr, $tag_name, $tag_attribs, $key, $text, $selected );
  1055. }
  1056. function makeOption( $value, $text='', $value_name='value', $text_name='text' ) {
  1057. $obj = new stdClass;
  1058. $obj->$value_name = $value;
  1059. $obj->$text_name = trim( $text ) ? $text : $value;
  1060. return $obj;
  1061. }
  1062. function selectList( $arr, $tag_name, $tag_attribs, $key, $text, $selected, $required=0 ) {
  1063. global $VM_LANG;
  1064. reset( $arr );
  1065. $html = "\n<select name=\"$tag_name\" id=\"".str_replace('[]', '', $tag_name)."\" $tag_attribs>";
  1066. if(!$required) $html .= "\n\t<option value=\"\">".$VM_LANG->_('PHPSHOP_SELECT')."</option>";
  1067. $n=count( $arr );
  1068. for ($i=0; $i < $n; $i++ ) {
  1069. $k = stripslashes($arr[$i]->$key);
  1070. $t = stripslashes($arr[$i]->$text);
  1071. $id = isset($arr[$i]->id) ? $arr[$i]->id : null;
  1072. $extra = '';
  1073. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1074. if (is_array( $selected )) {
  1075. foreach ($selected as $obj) {
  1076. $k2 = stripslashes($obj->$key);
  1077. if ($k == $k2) {
  1078. $extra .= " selected=\"selected\"";
  1079. break;
  1080. }
  1081. }
  1082. } else {
  1083. $extra .= ($k == stripslashes($selected) ? " selected=\"selected\"" : '');
  1084. }
  1085. $html .= "\n\t<option value=\"".$k."\"$extra>";
  1086. if( $t[0] == '_' ) $t = substr( $t, 1 );
  1087. $html .= $VM_LANG->exists($t) ? $VM_LANG->_($t) : $t;
  1088. $html .= "</option>";
  1089. }
  1090. $html .= "\n</select>\n";
  1091. return $html;
  1092. }
  1093. function checkboxListArr( $arr, $tag_name, $tag_attribs, $key='value', $text='text',$selected=null, $required=0 ) {
  1094. global $VM_LANG;
  1095. reset( $arr );
  1096. $html = array();
  1097. $n=count( $arr );
  1098. for ($i=0; $i < $n; $i++ ) {
  1099. $k = $arr[$i]->$key;
  1100. $t = $arr[$i]->$text;
  1101. $id = isset($arr[$i]->id) ? $arr[$i]->id : null;
  1102. $extra = '';
  1103. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1104. if (is_array( $selected )) {
  1105. foreach ($selected as $obj) {
  1106. $k2 = $obj->$key;
  1107. if ($k == $k2) {
  1108. $extra .= " checked=\"checked\"";
  1109. break;
  1110. }
  1111. }
  1112. } else {
  1113. $extra .= ($k == $selected ? " checked=\"checked\"" : '');
  1114. }
  1115. $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\">";
  1116. $tmp .= $VM_LANG->exists($t) ? $VM_LANG->_($t) : $t;
  1117. $tmp .= "</label>";
  1118. $html[] = $tmp;
  1119. }
  1120. return $html;
  1121. }
  1122. function checkboxList( $arr, $tag_name, $tag_attribs, $key='value', $text='text',$selected=null, $required=0 ) {
  1123. return "\n\t".implode("\n\t", vmCommonHTML::checkboxListArr( $arr, $tag_name, $tag_attribs, $key, $text,$selected, $required ))."\n";
  1124. }
  1125. function checkboxListTable( $arr, $tag_name, $tag_attribs, $key='value', $text='text',$selected=null, $cols=0, $rows=0, $size=0, $required=0 ) {
  1126. $cellsHtml = vmCommonHTML::checkboxListArr( $arr, $tag_name, $tag_attribs, $key, $text,$selected, $required );
  1127. return vmCommonHTML::list2Table( $cellsHtml, $cols, $rows, $size );
  1128. }
  1129. // private methods:
  1130. function list2Table ( $cellsHtml, $cols, $rows, $size ) {
  1131. $cells = count($cellsHtml);
  1132. if ($size == 0) {
  1133. $localstyle = ""; //" style='width:100%'";
  1134. } else {
  1135. $size = (($size-($size % 3)) / 3 ) * 2; // int div 3 * 2 width/heigh ratio
  1136. $localstyle = " style='width:".$size."em;'";
  1137. }
  1138. $return="";
  1139. if ($cells) {
  1140. if ($rows) {
  1141. $return = "\n\t<table class='vmMulti'".$localstyle.">";
  1142. $cols = ($cells-($cells % $rows)) / $rows; // int div
  1143. if ($cells % $rows) $cols++;
  1144. $lineIdx=0;
  1145. for ($lineIdx=0 ; $lineIdx < min($rows, $cells) ; $lineIdx++) {
  1146. $return .= "\n\t\t<tr>";
  1147. for ($i=$lineIdx ; $i < $cells; $i += $rows) {
  1148. $return .= "<td>".$cellsHtml[$i]."</td>";
  1149. }
  1150. $return .= "</tr>\n";
  1151. }
  1152. $return .= "\t</table>\n";
  1153. } else if ($cols) {
  1154. $return = "\n\t<table class='vmMulti'".$localstyle.">";
  1155. $idx=0;
  1156. while ($cells) {
  1157. $return .= "\n\t\t<tr>";
  1158. for ($i=0, $n=min($cells,$cols); $i < $n; $i++, $cells-- ) {
  1159. $return .= "<td>".$cellsHtml[$idx++]."</td>";
  1160. }
  1161. $return .= "</tr>\n";
  1162. }
  1163. $return .= "\t</table>\n";
  1164. } else {
  1165. $return = "\n\t".implode("\n\t ", $cellsHtml)."\n";
  1166. }
  1167. }
  1168. return $return;
  1169. }
  1170. // end class vmCommonHTML, thanks folks!
  1171. }
  1172. /**
  1173. * Utility function to provide ToolTips
  1174. *
  1175. * @param string $tooltip ToolTip text
  1176. * @param string $title The Box title
  1177. * @param string $image
  1178. * @param int $width
  1179. * @param string $text
  1180. * @param string $href
  1181. * @param string $link
  1182. * @return string HTML code for ToolTip
  1183. */
  1184. function vmToolTip( $tooltip, $title='Tip!', $image = "{mosConfig_live_site}/images/M_images/con_info.png", $width='350', $text='', $href='#', $link=false ) {
  1185. global $mosConfig_live_site, $database;
  1186. defined( 'vmToolTipCalled') or define('vmToolTipCalled', 1);
  1187. $tooltip = str_replace('"','&quot;',$tooltip);
  1188. $tooltip = $database->getEscaped($tooltip);
  1189. $tooltip = str_replace("&#039;","\&#039;",$tooltip);
  1190. if ( !empty($width) ) {
  1191. $width = ',WIDTH, -'.$width;
  1192. }
  1193. if ( $title ) {
  1194. $title = ',TITLE,\''.$title .'\'';
  1195. }
  1196. $image = str_replace( "{mosConfig_live_site}", $mosConfig_live_site, $image);
  1197. if( $image != '' ) {
  1198. $text = vmCommonHTML::imageTag( $image, '', 'absmiddle' ). '&nbsp;'.$text;
  1199. }
  1200. $style = 'style="text-decoration: none; color: #333;"';
  1201. if ( $href ) {
  1202. $style = '';
  1203. }
  1204. if ( $link ) {
  1205. $tip = vmCommonHTML::hyperLink( $href, $text, '','', "onmouseover=\"Tip( '$tooltip' );\" onmouseout=\"UnTip()\" ". $style );
  1206. } else {
  1207. $tip = "<span onmouseover=\"Tip( '$tooltip' $width $title );\" onmouseout=\"UnTip()\" ". $style .">". $text ."</span>";
  1208. }
  1209. return $tip;
  1210. }
  1211. /**
  1212. * @deprecated
  1213. */
  1214. 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 ); }
  1215. /**
  1216. * Utility function to provide persistant HelpToolTips
  1217. *
  1218. * @param unknown_type $tip
  1219. * @param unknown_type $linktext
  1220. */
  1221. function vmHelpToolTip( $tip, $linktext = ' [?] ' ) {
  1222. global $mosConfig_live_site;
  1223. if( !defined( 'vmHelpToolTipCalled')) {
  1224. echo '<script type="text/javascript" src="'.$mosConfig_live_site.'/components/com_virtuemart/js/helptip/helptip.js"></script>
  1225. <link type="text/css" rel="stylesheet" href="'.$mosConfig_live_site.'/components/com_virtuemart/js/helptip/helptip.css" />';
  1226. define('vmHelpToolTipCalled', 1);
  1227. }
  1228. $tip = str_replace( "\n", "",
  1229. str_replace( "&lt;", "<",
  1230. str_replace( "&gt;", ">",
  1231. str_replace( "&amp;", "&",
  1232. @htmlentities( $tip, ENT_QUOTES )))));
  1233. $varname = 'a'.md5( $tip );
  1234. echo '<script type="text/javascript">//<![CDATA[
  1235. var '.$varname.' = \''.$tip.'\';
  1236. //]]></script>
  1237. ';
  1238. echo '<a class="helpLink" href="?" onclick="showHelpTip(event, '.$varname.'); return false">'.$linktext.'</a>
  1239. ';
  1240. }
  1241. /**
  1242. * Converts all special chars to html entities
  1243. *
  1244. * @param string $string
  1245. * @param string $quote_style
  1246. * @param boolean $only_special_chars Only Convert Some Special Chars ? ( <, >, &, ... )
  1247. * @return string
  1248. */
  1249. function shopMakeHtmlSafe( $string, $quote_style='ENT_QUOTES', $use_entities=false ) {
  1250. if( defined( $quote_style )) {
  1251. $quote_style = constant($quote_style);
  1252. }
  1253. if( $use_entities ) {
  1254. $string = @htmlentities( $string, constant($quote_style), vmGetCharset() );
  1255. } else {
  1256. $string = @htmlspecialchars( $string, $quote_style, vmGetCharset() );
  1257. }
  1258. return $string;
  1259. }
  1260. function mm_showMyFileName( $filename ) {
  1261. if (vmShouldDebug()) { /*@MWM1: Logging/Debugging Enhancements */
  1262. echo vmToolTip( '<div class=\'inputbox\'>Begin of File: '. wordwrap( $filename, 70, '<br />', true ).'</div>');
  1263. }
  1264. }
  1265. /**
  1266. * Wraps HTML Code or simple Text into Javascript
  1267. * and uses the noscript Tag to support browsers with JavaScript disabled
  1268. **/
  1269. function mm_writeWithJS( $textToWrap, $noscriptText ) {
  1270. $text = "";
  1271. if( !empty( $textToWrap )) {
  1272. $text = "<script type=\"text/javascript\">//<![CDATA[
  1273. document.write(

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