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