Cheetah
ChQuotesModule.php
Go to the documentation of this file.
1 <?php
2 
8 require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbModule.php');
9 
11 {
12  // constructor
13  function __construct(&$aModule)
14  {
15  parent::__construct($aModule);
16  }
17 
19  {
20  $oQuoteUnit = $this->_oDb->getRandomQuote();
21 
22  $sUnitText = process_text_output($oQuoteUnit['Text']);
23  $sUnitAuthor = process_line_output($oQuoteUnit['Author']);
24 
25  $aVariables = array (
26  'unit_text' => $sUnitText,
27  'author' => $sUnitAuthor
28  );
29 
30  $this->_oTemplate->addCss('unit.css');
31  return array($this->_oTemplate->parseHtmlByTemplateName('unit', $aVariables), array(), array(), false);
32  }
33 
34  function actionAdministration($sSubaction = '', $sID = 0)
35  {
37 
38  require_once(CH_DIRECTORY_PATH_INC . 'admin_design.inc.php');
39  $logged['admin'] = member_auth( 1, true, true );
40 
41  $iUnitID = ($sSubaction == 'edit' && (int)$sID > 0) ? (int)$sID : 0;
42  $iUnitID = (ch_get('action') == 'edit' && (int)ch_get('ID') > 0) ? (int)ch_get('ID') : $iUnitID;
43 
44  if (isset($_POST['quotes_list']) && is_array($_POST['quotes_list'])) { // manage subactions
45  foreach($_POST['quotes_list'] as $sQuoteId) {
46  $iQuoteId = (int)$sQuoteId;
47  switch (true) {
48  case isset($_POST['action_delete']):
49  $this->_oDb->deleteUnit($iQuoteId);
50  break;
51  }
52  }
53  }
54 
55  $iNameIndex = 9;
56  $_page = array(
57  'name_index' => $iNameIndex,
58  'css_name' => array(),
59  'js_name' => array(),
60  'header' => _t('_adm_page_cpt_quotes'),
61  'header_text' => _t('_adm_box_cpt_quotes')
62  );
63  $_page_cont[$iNameIndex]['page_main_code'] = $this->getPostForm($iUnitID);
64  $_page_cont[$iNameIndex]['page_main_code'] .= $this->getQuotesList();
65 
66  PageCodeAdmin();
67  }
68 
69  function getPostForm($iUnitID = 0)
70  {
71  $sAddNewC = _t('_ch_quotes_add_new');
72 
73  $sAction = 'add';
74  $sQText = $sQText = '';
75 
76  if ($iUnitID) {
77  $aQinfo = $this->_oDb->getQuote($iUnitID);
78  $sQText = $aQinfo['Text'];
79  $sQAuthor = $aQinfo['Author'];
80  $sAction = 'edit';
81  }
82 
83  $aForm = array(
84  'form_attrs' => array(
85  'name' => 'create_quotes_form',
86  'action' => CH_WSB_URL_ROOT . 'modules/?r=quotes/administration/',
87  'method' => 'post',
88  ),
89  'params' => array (
90  'db' => array(
91  'table' => 'ch_quotes_units',
92  'key' => 'ID',
93  'submit_name' => 'add_button',
94  ),
95  ),
96  'inputs' => array(
97  'action' => array(
98  'type' => 'hidden',
99  'name' => 'action',
100  'value' => $sAction,
101  ),
102  'Text' => array(
103  'type' => 'textarea',
104  'name' => 'Text',
105  'caption' => _t('_ch_quotes_text'),
106  'required' => true,
107  'value' => $sQText,
108  'checker' => array (
109  'func' => 'length',
110  'params' => array(3,1024),
111  'error' => _t('_ch_quotes_text_err', 1024),
112  ),
113  'db' => array (
114  'pass' => 'Xss',
115  ),
116  ),
117  'Author' => array(
118  'type' => 'text',
119  'name' => 'Author',
120  'caption' => _t('_ch_quotes_author'),
121  'required' => true,
122  'value' => $sQAuthor,
123  'checker' => array (
124  'func' => 'length',
125  'params' => array(3,128),
126  'error' => _t('_ch_quotes_author_err', 128),
127  ),
128  'db' => array (
129  'pass' => 'Xss',
130  ),
131  ),
132  'add_button' => array(
133  'type' => 'submit',
134  'name' => 'add_button',
135  'value' => _t('_Submit'),
136  ),
137  ),
138  );
139 
140  if ($iUnitID) {
141  $aForm['inputs']['hidden_unitid'] = array(
142  'type' => 'hidden',
143  'name' => 'ID',
144  'value' => $iUnitID,
145  );
146  }
147 
148  $sCode = '';
149 
151  $oForm->initChecker();
152  if ($oForm->isSubmittedAndValid()) {
153 
154  $sCode = MsgBox(_t('_ch_quotes_fail'), 1);
155 
156  $aValsAdd = array ();
157 
158  $iLastId = -1;
159  if ($iUnitID>0) {
160  $oForm->update($iUnitID, $aValsAdd);
161  $iLastId = $iUnitID;
162  $sCode = MsgBox(_t('_ch_quotes_edited_success'), 1);
163  } else {
164  $iLastId = $oForm->insert($aValsAdd);
165  $sCode = MsgBox(_t('_ch_quotes_success'), 1);
166  }
167  }
168 
169  return DesignBoxAdmin($sAddNewC, $sCode . $oForm->getCode(), '', '', 11);
170  }
171 
172  function getQuotesList()
173  {
174  $sExistedC = _t('_ch_quotes_existed_list');
175 
176  if (isset($GLOBALS['oAdmTemplate'])) {
177  $GLOBALS['oAdmTemplate']->addDynamicLocation($this->_oConfig->getHomePath(), $this->_oConfig->getHomeUrl());
178  $GLOBALS['oAdmTemplate'] -> addCss('unit.css');
179  }
180 
181  $sAction = CH_WSB_URL_ROOT . 'modules/?r=quotes/administration/';
182 
183  $iCnt = 0;
184  $aAllQuotes = $this->_oDb->getAllQuotes();
185  foreach ($aAllQuotes as $iID => $aQuoteInfo) {
186  $sBgClr = ($iID % 2 == 0) ? '#EEE' : '#FFF';
187  $iQId = (int)$aQuoteInfo['ID'];
188  $sQText = process_line_output($aQuoteInfo['Text']);
189  $sQAuthor = process_line_output($aQuoteInfo['Author']);
190 
191  $aVariables = array (
192  'bg_clr' => $sBgClr,
193  'unit_id' => $iQId,
194  'unit_author' => $sQAuthor,
195  'action_url' => $sAction,
196  'unit_text' => $sQText
197  );
198  $sQuotes .= $this->_oTemplate->parseHtmlByTemplateName('adm_unit', $aVariables);
199  }
200 
201  ch_import('ChTemplSearchResult');
202  $oSearchResult = new ChTemplSearchResult();
203  $sAdmPanel = $oSearchResult->showAdminActionsPanel('quotes_box', array('action_delete' => '_Delete'), 'quotes_list');
204 
205  $sCode = <<<EOF
206 <form action="{$sAction}" method="post" name="quotes_moderation">
207  <div class="adm-db-content-wrapper ch-def-bc-margin">
208  <div id="quotes_box">
209  {$sQuotes}
210  <div class="clear_both"></div>
211  </div>
212  </div>
213  {$sAdmPanel}
214 </form>
215 EOF;
216 
217  ch_import('ChWsbPageView');
218  $sActions = /*ChWsbPageView::getBlockCaptionMenu(time(),*/ array(
219  'add_unit' => array('href' => $sAction, 'title' => _t('_ch_quotes_add_new'), 'onclick' => '', 'active' => 0),
220  )/*)*/;
221  return DesignBoxAdmin($sExistedC, $sCode, $sActions);
222  }
223 }
ChTemplFormView
Definition: ChTemplFormView.php:11
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
name
Core AllowHostnameUnderscore underscores are not permitted in host most browsers do the right thing when faced with an underscore in the host name
Definition: Core.AllowHostnameUnderscore.txt:11
$sCode
$sCode
Definition: explanation.php:19
$aModule
$aModule
Definition: classifieds.php:21
$_page
$_page['name_index']
Definition: about_us.php:13
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChQuotesModule\getPostForm
getPostForm($iUnitID=0)
Definition: ChQuotesModule.php:69
$_page_cont
$_page_cont[$_ni]['page_main_code']
Definition: about_us.php:24
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
php
ChQuotesModule
Definition: ChQuotesModule.php:11
ChQuotesModule\serviceGetQuoteUnit
serviceGetQuoteUnit()
Definition: ChQuotesModule.php:18
$oForm
$oForm
Definition: host_tools.php:42
DesignBoxAdmin
DesignBoxAdmin($sTitle, $sContent, $mixedTopItems='', $sBottomItems='', $iIndex=1)
Definition: admin_design.inc.php:50
ChTemplSearchResult
Definition: ChTemplSearchResult.php:11
ChQuotesModule\getQuotesList
getQuotesList()
Definition: ChQuotesModule.php:172
process_text_output
process_text_output($text, $maxwordlen=100)
Definition: utils.inc.php:313
ChQuotesModule\__construct
__construct(&$aModule)
Definition: ChQuotesModule.php:13
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChWsbModule
Definition: ChWsbModule.php:41
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
method
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step method
Definition: license.txt:49
process_line_output
process_line_output($text, $maxwordlen=100)
Definition: utils.inc.php:328
ChQuotesModule\actionAdministration
actionAdministration($sSubaction='', $sID=0)
Definition: ChQuotesModule.php:34
$logged
$logged['member']
Definition: activation_email.php:16
$aForm
$aForm
Definition: forgot.php:43
$sAction
$sAction
Definition: categories.php:274
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$iNameIndex
$iNameIndex
Definition: admin_tools.php:39
form
iii in the case of the organization that transmits the broadcast Work means the literary and or artistic work offered under the terms of this License including without limitation any production in the scientific and artistic whatever may be the mode or form of its expression including digital form
Definition: license.txt:19
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10