Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.Helppage.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: Method.DocText.php,v 1.2 2003/08/18 15:47:04 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: Method.DocText.php,v 1.2 2003/08/18 15:47:04 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/freedom/Class/Fdl/Method.DocText.php,v $
21 // ---------------------------------------------------------------
22 
23 /**
24  * @begin-method-ignore
25  * this part will be deleted when construct document class until end-method-ignore
26  */
27 class _HELPPAGE extends Doc
28 {
29  /*
30  * @end-method-ignore
31  */
32 
33  public $defaultview = 'FDL:VIEWHELPPAGE:T';
34  public $defaultedit = 'FDL:EDITHELPPAGE';
35  /**
36  *
37  * @return string
38  */
39  public function getSpecTitle()
40  {
41  $titles = $this->getHelpByLang();
42  $user_lang = $this->getUserLang();
43  if (count($titles) == 0) {
44  return $this->title;
45  }
46  if (array_key_exists($user_lang, $titles)) {
47  if ($titles[$user_lang]['help_name']) return $titles[$user_lang]['help_name'];
48  } else {
49  $item = array_shift($titles);
50  if ($item['help_name']) return $item['help_name'];
51  }
52  return $this->title;
53  }
54  /**
55  *
56  */
57  public function preEdition()
58  {
59  $oa = $this->getAttribute('help_sec_text');
60  $oa->type = 'longtext';
61  $err = '';
62  if (!$this->id) {
63 
64  $oa = $this->getAttribute('help_family');
65  $oa->setVisibility('S');
66  }
67  if ($this->id == 0) {
68  $doc = createDoc($this->dbaccess, $this->fromid);
69  if ($doc) {
70  $err = $doc->add();
71  if ($err == "") {
72  $this->Affect(getTdoc($this->dbaccess, $doc->id));
73 
74  $this->setValue("help_family", getHttpVars("help_family"));
75  if ($this->getValue("help_family")) $this->title = sprintf(_("help for %s") , $this->getTitle($this->getValue("help_family")));
76 
77  $this->modify();
78  global $action;
79  redirect($action, getHttpVars("app") , getHttpVars("action") . '&id=' . $this->id);
80  }
81  }
82  }
83  return $err;
84  }
85  /**
86  *
87  * @return array
88  */
89  public function getSectionsByLang()
90  {
91  $rows = $this->getAValues('help_t_sections');
92 
93  $sections = array();
94  foreach ($rows as $row) {
95  $key = str_pad($row['help_sec_order'], 8, '0', STR_PAD_LEFT) . $row['help_sec_key'];
96  $sections[$key][$row['help_sec_lang']] = $row;
97  }
98  ksort($sections);
99 
100  return $sections;
101  }
102  /**
103  *
104  * @return array
105  */
106  public function getFamilyLangs()
107  {
108  $all_lang_keys = $this->_val2array($this->getParamValue('help_p_lang_key'));
109  $all_lang_texts = $this->_val2array($this->getParamValue('help_p_lang_name'));
110  $all_langs = array();
111  foreach ($all_lang_keys as $i => $key) {
112  $all_langs[$key] = $all_lang_texts[$i];
113  }
114  return $all_langs;
115  }
116  /**
117  *
118  * @global $action
119  * @return string
120  */
121  public function getUserLang()
122  {
123  global $action;
124  $user_lang = $action->getParam('CORE_LANG');
125  return $user_lang;
126  }
127  /**
128  *
129  * @return array
130  */
131  public function getHelpByLang()
132  {
133  $rows = $this->getAValues('help_t_help');
134 
135  $helps = array();
136  foreach ($rows as $row) {
137  $helps[$row['help_lang']] = $row;
138  }
139 
140  return $helps;
141  }
142  /**
143  *
144  */
145  public function edithelppage()
146  {
147  $this->editattr();
148  $langs = $this->getFamilyLangs();
149  $user_lang = $this->getUserLang();
150  $sections = $this->getSectionsByLang();
151 
152  $this->editattr();
153 
154  $help_values = $this->getHelpByLang();
155  // set help values
156  $helpname = '';
157  $helplangiso = '';
158  $lang_key = '';
159  // search user lang
160  foreach ($help_values as $lang => $help) {
161  if ($lang == $user_lang) {
162  $lang_key = $lang;
163  $helpname = $help['help_name'];
164  $helpdescription = $help['help_description'];
165  break;
166  }
167  }
168  if (empty($lang_key)) {
169  // search first lang
170  foreach ($help_values as $lang => $help) {
171  $lang_key = $lang;
172  $helpname = $help['help_name'];
173  $helpdescription = $help['help_description'];
174  }
175  }
176  $this->lay->set('HELPID', $this->id);
177  $this->lay->set('HELPNAME', $helpname);
178  $this->lay->set('HELPDESCRIPTION', $helpdescription);
179  // help add section
180  $famid = $this->getValue('help_family');
181  if (empty($famid)) {
182  $this->lay->set('HELPATTRIBUTESLIST', false);
183  } else {
184  $this->lay->set('HELPATTRIBUTESLIST', true);
185  $docfam = createDoc($this->dbaccess, $famid, false);
186  $docattributes = $docfam->GetNormalAttributes();
187  $attributes = array();
188  foreach ($docattributes as $attribute) {
189  $attributes[] = array(
190  'HELPATTRVALUE' => $attribute->id,
191  'HELPATTRNAME' => $attribute->getLabel() ,
192  );
193  }
194  $this->lay->SetBlockData('HELPATTRIBUTES', $attributes);
195  }
196 
197  $this->lay->SetBlockData('HELPLANGS', $this->getLangsFromItem($langs, $lang_key, $help_values));
198  $this->lay->set('JSONLANGS', json_encode($langs));
199  // construct sections
200  $n = count($langs) - 1;
201  $contentsection = array();
202  foreach ($sections as $section) {
203  $sec_key = $this->getSectionKey($section);
204  $first_lang = $this->getFirstSectionLang($section, $user_lang);
205  $secitems = array();
206  $i = 0;
207  foreach ($langs as $lang_key => $lang_name) {
208  if (array_key_exists($lang_key, $section)) {
209  $sec = $section[$lang_key];
210  } else {
211  $sec = array(
212  'help_sec_key' => $sec_key,
213  'help_sec_name' => '',
214  'help_sec_lang' => $lang_key,
215  'help_sec_text' => '',
216  );
217  }
218  $secitems[] = array(
219  'SECNAME' => $sec['help_sec_name'],
220  'SECLANG' => $sec['help_sec_lang'],
221  'SECTEXT' => $sec['help_sec_text'],
222  'SECDISPLAY' => $lang_key == $first_lang ? 'block' : 'none',
223  );
224  $i++;
225  }
226  $contentsection[] = array(
227  'SECKEY' => $sec_key,
228  'SECTIONLANGS' => 'seclangs' . $sec_key,
229  'SECTIONITEMS' => 'secitems' . $sec_key,
230  );
231  $this->lay->setBlockData('seclangs' . $sec_key, $this->getLangsFromItem($langs, $first_lang, $section));
232  $this->lay->setBlockData('secitems' . $sec_key, $secitems);
233  }
234  $this->lay->setBlockData('CONTENTSECTIONS', $contentsection);
235 
236  $langitems = array();
237  $first = true;
238  foreach ($langs as $lang_key => $lang_name) {
239  $langitems[] = array(
240  'LANGKEY' => $lang_key,
241  'LANGISO' => strtolower(substr($lang_key, -2)) ,
242  'LANGNAME' => $lang_name,
243  'LANGCLASS' => $first ? 'current' : 'inactive',
244  'LANGDISPLAY' => $first ? 'block' : 'none',
245  );
246  $first = false;
247  }
248  $this->lay->setBlockData('TEMPLATELANGS1', $langitems);
249  $this->lay->setBlockData('TEMPLATELANGS2', $langitems);
250  }
251  /**
252  *
253  * @global <type> $action
254  * @param <type> $target
255  * @param <type> $ulink
256  * @param <type> $abstract
257  */
258  public function printhelppage($target = "_self", $ulink = true, $abstract = false)
259  {
260  $this->viewhelppage($target, $ulink, $abstract);
261  }
262  /**
263  *
264  * @global <type> $action
265  * @param <type> $target
266  * @param <type> $ulink
267  * @param <type> $abstract
268  */
269  public function viewhelppage($target = "_self", $ulink = true, $abstract = false)
270  {
271  global $action;
272 
273  include_once ("FDL/Class.SearchDoc.php");
274 
275  $this->lay->set('HELPTITLE', $this->getTitle());
276  $this->lay->set('DOCID', $this->id);
277 
278  if ($this->CanEdit() == '') {
279  $this->lay->set('HELPEDITABLE', '1');
280  if ($action->getArgument('target') == 'ext') {
281  $this->lay->set('HELPEDITURI', '?app=FDL&action=EDITEXTDOC&viewext=yes&id=' . $this->id);
282  } else {
283  $this->lay->set('HELPEDITURI', '?app=GENERIC&action=GENERIC_EDIT&id=' . $this->id);
284  }
285  } else {
286  $this->lay->set('HELPEDITABLE', '0');
287  $this->lay->set('HELPEDITURI', '');
288  }
289 
290  $langs = $this->getFamilyLangs();
291  $user_lang = $this->getUserLang();
292  $sections = $this->getSectionsByLang();
293  // construct sections on the right
294  $leftsection = array();
295  $contentsection = array();
296  $i = 0;
297  foreach ($sections as $section) {
298  // get first lang
299  $first_lang = $this->getFirstSectionLang($section, $user_lang);
300  $ifirst = - 1;
301  $ilast = - 1;
302  foreach ($langs as $lang_key => $lang_name) {
303  // construct section
304  if (array_key_exists($lang_key, $section)) {
305  $sec = $section[$lang_key];
306  if ($lang_key == $first_lang) {
307  $leftsection[] = array(
308  'SECKEY' => $sec['help_sec_key'],
309  'SECNAME' => $sec['help_sec_name'],
310  'SECLANG' => $sec['help_sec_lang'],
311  );
312  }
313  if ($ifirst < 0) {
314  $ifirst = $i;
315  }
316  $contentsection[] = array(
317  'SECKEY' => $sec['help_sec_key'],
318  'SECNAME' => $sec['help_sec_name'],
319  'SECLANG' => $sec['help_sec_lang'],
320  'SECTEXT' => $this->getHtmlValue($this->getAttribute('help_sec_text') , $sec['help_sec_text']) ,
321  'SECDISPLAY' => $lang_key == $first_lang ? 'block' : 'none',
322  'SECLANGS' => 'seclangs' . $i,
323  'SECHEADER' => '0',
324  'SECFOOTER' => '0',
325  );
326  $ilast = $i;
327  $this->lay->setBlockData('seclangs' . $i, $this->getLangsFromItem($langs, $lang_key, $section));
328  $i++;
329  }
330  }
331  if ($ifirst >= 0 && $ilast >= 0) {
332  $contentsection[$ifirst]['SECHEADER'] = '1';
333  $contentsection[$ilast]['SECFOOTER'] = '1';
334  }
335  }
336 
337  $this->lay->setBlockData('LEFTSECTIONS', $leftsection);
338 
339  $this->lay->setBlockData('CONTENTSECTIONS', $contentsection);
340  $this->lay->setBlockData('JSSECTIONS', $contentsection);
341 
342  $all_langs = array();
343  foreach ($langs as $lang_key => $lang_name) {
344  $all_langs[] = array(
345  'LANGKEY' => $lang_key,
346  'LANGNAME' => $lang_name,
347  'LANGISO' => strtolower(substr($lang_key, -2)) ,
348  );
349  }
350  $this->lay->setBlockData('ALLLANGS', $all_langs);
351 
352  $descriptions = $this->getAvalues("help_t_help");
353  $first = true;
354  foreach ($descriptions as & $v) {
355  $v["firstdesc"] = $first;
356  if ($v["help_description"]) {
357  $first = false;
358  }
359  }
360  $this->lay->setBlockData('DESCR', $descriptions);
361 
362  $first = true;
363  foreach ($descriptions as & $v) {
364  $v["firsttitle"] = $first;
365  if ($v["help_name"]) {
366  $first = false;
367  }
368  }
369  $this->lay->setBlockData('TITLES', $descriptions);
370  // construct aides
371  $aides = array();
372  $s = new SearchDoc($this->dbaccess, 'HELPPAGE');
373  $s->setObjectReturn();
374  $s->orderby = 'title';
375  $s->search();
376  while ($doc = $s->nextDoc()) {
377  $aides[] = array(
378  'AIDE' => $doc->getDocAnchor($doc->id, $target, true, false, false) ,
379  );
380  }
381  $this->lay->setBlockData('LEFTHELPS', $aides);
382  }
383  /**
384  *
385  * @param Array $all_lang_keys
386  * @param Array $all_lang_texts
387  * @param string $current_lang
388  * @param string $item
389  * @return array
390  */
391  public function getLangsFromItem($all_langs, $current_lang, $item)
392  {
393 
394  $langs = array();
395  foreach ($all_langs as $lang_key => $lang_name) {
396  if ($lang_key == $current_lang) {
397  $langclass = 'current';
398  } elseif (array_key_exists($lang_key, $item)) {
399  $langclass = 'active';
400  } else {
401  $langclass = 'inactive';
402  }
403  $langs[] = array(
404  'LANGKEY' => $lang_key,
405  'LANGNAME' => $lang_name,
406  'LANGCLASS' => $langclass,
407  'LANGISO' => strtolower(substr($lang_key, -2)) ,
408  );
409  }
410  return $langs;
411  }
412  /**
413  *
414  * @param string $section
415  * @param string $user_lang
416  * @return string
417  */
418  public function getFirstSectionLang($section, $user_lang)
419  {
420  // return lang if found
421  foreach ($section as $lang => $sec) {
422  if ($lang == $user_lang) {
423  return $lang;
424  }
425  }
426  // return first lang
427  foreach ($section as $lang => $sec) {
428  return $lang;
429  }
430  }
431  /**
432  *
433  * @param string $section
434  * @return string
435  */
436  public function getSectionKey($section)
437  {
438  foreach ($section as $lang => $sec) {
439  return $sec['help_sec_key'];
440  }
441  return false;
442  }
443  /**
444  * @begin-method-ignore
445  * this part will be deleted when construct document class until end-method-ignore
446  */
447 }
448 /*
449  * @end-method-ignore
450 */
451 ?>
← centre documentaire © anakeen - published under CC License - Dynacase