PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_contact/tables/contact.php

https://github.com/joebushi/joomla
PHP | 167 lines | 85 code | 13 blank | 69 comment | 16 complexity | e29e4ee399424c162ff4a3cf6c847af8 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Administrator
  5. * @subpackage Contact
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access
  10. defined('_JEXEC') or die;
  11. /**
  12. * @package Joomla.Administrator
  13. * @subpackage Contact
  14. */
  15. class ContactTableContact extends JTable
  16. {
  17. /** @var int Primary key */
  18. public $id = null;
  19. /** @var string */
  20. public $name = null;
  21. /** @var string */
  22. public $alias = null;
  23. /** @var string */
  24. public $con_position = null;
  25. /** @var string */
  26. public $address = null;
  27. /** @var string */
  28. public $suburb = null;
  29. /** @var string */
  30. public $state = null;
  31. /** @var string */
  32. public $country = null;
  33. /** @var string */
  34. public $postcode = null;
  35. /** @var string */
  36. public $telephone = null;
  37. /** @var string */
  38. public $fax = null;
  39. /** @var string */
  40. public $misc = null;
  41. /** @var string */
  42. public $image = null;
  43. /** @var string */
  44. public $imagepos = null;
  45. /** @var string */
  46. public $email_to = null;
  47. /** @var int */
  48. public $default_con = null;
  49. /** @var int */
  50. public $published = 0;
  51. /** @var int */
  52. public $checked_out = 0;
  53. /** @var datetime */
  54. public $checked_out_time = 0;
  55. /** @var int */
  56. public $ordering = null;
  57. /** @var string */
  58. public $params = null;
  59. /** @var int A link to a registered user */
  60. public $user_id = null;
  61. /** @var int A link to a category */
  62. public $catid = null;
  63. /** @var int */
  64. public $access = null;
  65. /** @var string Mobile phone number(s) */
  66. public $mobile = null;
  67. /** @var string */
  68. public $webpage = null;
  69. /** @var string */
  70. public $sortname1 = null;
  71. /** @var string */
  72. public $sortname2 = null;
  73. /** @var string */
  74. public $sortname3 = null;
  75. /** @var string */
  76. public $language = null;
  77. /**
  78. * Constructor
  79. *
  80. * @param object Database connector object
  81. * @since 1.0
  82. */
  83. public function __construct(& $db)
  84. {
  85. parent::__construct('#__contact_details', 'id', $db);
  86. }
  87. /**
  88. * Stores a contact
  89. *
  90. * @param boolean $updateNulls Toggle whether null values should be updated.
  91. * @return boolean True on success, false on failure.
  92. * @since 1.6
  93. */
  94. public function store($updateNulls = false){
  95. // Transform the params field
  96. if (is_array($this->params)) {
  97. $registry = new JRegistry();
  98. $registry->loadArray($this->params);
  99. $this->params = $registry->toString();
  100. }
  101. // Attempt to store the data.
  102. return parent::store($updateNulls);
  103. }
  104. /**
  105. * Overloaded check function
  106. *
  107. * @return boolean
  108. * @see JTable::check
  109. * @since 1.5
  110. */
  111. function check()
  112. {
  113. $this->default_con = intval($this->default_con);
  114. if (JFilterInput::checkAttribute(array ('href', $this->webpage))) {
  115. $this->setError(JText::_('CONTACT_WARNING_PROVIDE_VALID_URL'));
  116. return false;
  117. }
  118. // check for http, https, ftp on webpage
  119. if ((strlen($this->webpage) > 0)
  120. && (stripos($this->webpage, 'http://') === false)
  121. && (stripos($this->webpage, 'https://') === false)
  122. && (stripos($this->webpage, 'ftp://') === false))
  123. {
  124. $this->webpage = 'http://'.$this->webpage;
  125. }
  126. // check for http on additional links
  127. /** check for valid name */
  128. if (trim($this->name) == '') {
  129. $this->setError(JText::_('CONTACT_WARNING_NAME'));
  130. return false;
  131. }
  132. /** check for existing name */
  133. $query = 'SELECT id FROM #__contact_details WHERE name = '.$this->_db->Quote($this->name).' AND catid = '.(int) $this->catid;
  134. $this->_db->setQuery($query);
  135. $xid = intval($this->_db->loadResult());
  136. if ($xid && $xid != intval($this->id)) {
  137. $this->setError(JText::sprintf('Contact_Warning_Same_Name', JText::_('Contact')));
  138. return false;
  139. }
  140. if (empty($this->alias)) {
  141. $this->alias = $this->name;
  142. }
  143. $this->alias = JApplication::stringURLSafe($this->alias);
  144. if (trim(str_replace('-','',$this->alias)) == '') {
  145. $this->alias = JFactory::getDate()->toFormat("%Y-%m-%d-%H-%M-%S");
  146. }
  147. /** check for valid category */
  148. if (trim($this->catid) == '') {
  149. $this->setError(JText::_('CONTACT_WARNING_CATEGORY'));
  150. return false;
  151. }
  152. return true;
  153. }
  154. }