Esempio n. 1
0
 /**
  * Order the tree recursivly after generating the
  * rawdata.  
  * @param integer $parent 
  * @param integer $level
  * @return boolean Returns TRUE on success, otherwise returns FALSE.
  */
 protected function _treeOrder($parent, $level = 0, $parent_replace = FALSE)
 {
     if ($level > $this->data['level_max']) {
         $this->data['level_max'] = $level;
     }
     if (is_array($this->data['rawdata'][$parent])) {
         foreach ($this->data['rawdata'][$parent] as $index => $id) {
             $perm_ok = TRUE;
             if ($this->treecfg['perm']['active']) {
                 $perm_ok = $this->cfg->perm()->have_perm($this->treecfg['perm']['nr'], $this->treecfg['perm']['type'], $id);
             }
             if ($perm_ok) {
                 $this->data['items_levelorder'][] = $id;
                 $this->_incrementLevelCount($level);
                 $this->data['items_level'][$id] = $level;
                 $this->data['items_sortindex'][$id] = $sortindex;
                 if (is_array($this->data['rawdata'][$id])) {
                     $this->_treeOrder($id, $level + 1);
                 }
             } else {
                 if (is_array($this->data['rawdata'][$id])) {
                     $this->_treeOrder($id, $level);
                 }
                 unset($this->data['rawdata'][$parent][$index]);
                 unset($this->data['parents'][$id]);
             }
         }
         array_push($this->data['last_items'], $id);
     }
     return TRUE;
 }
Esempio n. 2
0
 /**
  * Iterate through $config_fields and set the matched values from $item.
  * @global $sf_factory API-Factory to instanciate the editors
  * @param array $config_fields Configuration of all fields as array 
  * @param SF_INTERFACE_Item $item Item that uses the interface
  * @param boolean $form_was_send
  * @return array Returns the given $config_fields with added values.
  */
 protected function _assignValuesToConfigFields($config_fields, $item, $form_was_send = FALSE)
 {
     global $sf_factory;
     //get form vals
     foreach ($config_fields as $k => $v) {
         //show if type exists
         if (!array_key_exists('type', $v)) {
             continue;
         }
         //filter type
         switch ($v['type']) {
             case 'headline':
             case 'info':
                 continue;
                 break;
             case 'hidden':
             case 'text':
             case 'textarea':
             case 'cmslink':
             case 'directorychooser':
                 $item_val = $item === null ? '' : $this->req->req($k, $item->getField($k));
                 if ($item_val == '') {
                     continue;
                 }
                 $config_fields[$k]['val'] = $item_val;
                 break;
             case 'infofield':
                 if ($v['format'] == '') {
                     $item_val = $item === null ? '' : $this->req->req($k, $item->getField($k));
                 } else {
                     if ($item !== null && $item->getField($k) != '') {
                         // format created and lastmodified
                         switch ($k) {
                             case 'created':
                                 $date = $item->getCreatedDate();
                                 $time = $item->getCreatedTime();
                                 $author = $item->getCreatedAuthor('', 'username');
                                 break;
                             case 'lastmodified':
                                 $date = $item->getLastmodifiedDate();
                                 $time = $item->getLastmodifiedTime();
                                 $author = $item->getLastmodifiedAuthor('', 'username');
                                 break;
                             default:
                                 $author = $time = $date = $this->req->req($k, $item->getField($k));
                                 break;
                         }
                         $item_val = str_replace('{date}', $date, $v['format']);
                         $item_val = str_replace('{time}', $time, $item_val);
                         $item_val = str_replace('{author}', $author, $item_val);
                     }
                 }
                 if ($item_val == '') {
                     continue;
                 }
                 $config_fields[$k]['val'] = $item_val;
                 break;
                 // TODO This works just with one checkbox per line at the moment. Extend it the assign behavior to use multiple checkboxes. Remove this todo afterwards.
                 // Note: Multiple checkboxes are already implemented in the API/VIEWS/Form.php and form_elements.tpl
             // TODO This works just with one checkbox per line at the moment. Extend it the assign behavior to use multiple checkboxes. Remove this todo afterwards.
             // Note: Multiple checkboxes are already implemented in the API/VIEWS/Form.php and form_elements.tpl
             case 'checkbox':
                 if ($form_was_send == TRUE && $this->req->req($k, FALSE) !== FALSE) {
                     $config_fields[$k]['checked'] = array_key_exists($this->req->req($k), $config_fields[$k]['val']);
                 } else {
                     if ($item !== null && array_key_exists($item->getField($k), $config_fields[$k]['val']) == TRUE) {
                         $config_fields[$k]['checked'] = TRUE;
                     } else {
                         $config_fields[$k]['checked'] = FALSE;
                     }
                 }
                 break;
             case 'radio':
                 if ($form_was_send && $this->req->req($k, FALSE) !== FALSE) {
                     $config_fields[$k]['checked'] = $this->req->req($k) == $config_fields[$k]['val'];
                 } else {
                     if ($item !== null && $item->getField($k) == $config_fields[$k]['val']) {
                         $config_fields[$k]['checked'] = TRUE;
                     } else {
                         $config_fields[$k]['checked'] = FALSE;
                     }
                 }
                 break;
                 // TODO This works just with single selects at the moment. Extend it the assign behavior to use multiple selectes. Remove this todo afterwards.
                 // Note: Multiple selects are already implemented in the API/VIEWS/Form.php and form_elements.tpl
             // TODO This works just with single selects at the moment. Extend it the assign behavior to use multiple selectes. Remove this todo afterwards.
             // Note: Multiple selects are already implemented in the API/VIEWS/Form.php and form_elements.tpl
             case 'select':
                 $item_val = $item === null ? '' : $this->req->req($k, $item->getField($k));
                 if ($item_val == '') {
                     continue;
                 }
                 $config_fields[$k]['selected'] = $item_val;
                 break;
             case 'rightspanel':
                 $config = array_key_exists('panel_config', $config_fields[$k]) ? $config_fields[$k]['panel_config'] : array();
                 // formname is set in function _buildFormFromConfigFields()
                 $config['formname'] = 'edit';
                 $view = array_key_exists('panel_view', $config_fields[$k]) ? $config_fields[$k]['panel_view'] : 'text';
                 $panel_arr = $this->cfg->perm()->get_right_panel($item->getObjectPermType(), $item->getId(), $config, $view);
                 // show panel only if generated and editing the item
                 if (empty($panel_arr) == FALSE && $item->getId() > 0) {
                     $config_fields[$k]['panel'] = implode('', $panel_arr);
                 } else {
                     $config_fields[$k]['panel'] = null;
                 }
                 unset($config, $view, $panel_arr);
                 break;
             case 'editor':
                 // create editor if exists, store instance and set item if allowed
                 if ($item !== null && array_key_exists('editor_type', $config_fields[$k]) && $config_fields[$k]['editor_instance'] == null && $sf_factory->classExists('VIEW', $config_fields[$k]['editor_type'])) {
                     $config_fields[$k]['editor_instance'] = sf_api('VIEW', $config_fields[$k]['editor_type']);
                     // the editor must be an item editor (that deals only with one item)
                     if ($config_fields[$k]['editor_instance'] instanceof SF_INTERFACE_ItemEditor) {
                         $config_fields[$k]['editor_config'] = !array_key_exists('editor_config', $config_fields[$k]) ? array() : $config_fields[$k]['editor_config'];
                         $config_fields[$k]['editor_instance']->setEditorName($k);
                         $config_fields[$k]['editor_instance']->setConfig($config_fields[$k]['editor_config']);
                         if ($config_fields[$k]['editor_instance']->isItemAllowed($item)) {
                             $config_fields[$k]['editor_instance']->setItem($item);
                         }
                     } else {
                         $config_fields[$k]['editor_instance'] = null;
                     }
                 } else {
                     $config_fields[$k]['editor_instance'] = null;
                 }
                 break;
         }
     }
     return $config_fields;
 }
 /**
  * Generate a SQL statement to set the perm limits
  * @return string Returns the piece of the SQL statement.
  * If an error occurs it returns an empty string.
  */
 protected function _getSqlPerms()
 {
     static $sql_perms = '';
     //perms are allready generated, return the string
     if ($sql_perms != '') {
         return $sql_perms;
     }
     //init perms with nothing
     $sql_perms = ' ';
     //Check if permcheck is enabled
     if (!$this->colcfg['perm_check_active']) {
         return $sql_perms;
     }
     //TODO make it for other clients/langs work
     if (TRUE) {
         $perm = $this->cfg->perm();
     } else {
         //TODO $client, $lang
         $perm = new cms_perms($client, $lang, TRUE, $this->cfg->perm()->get_group());
     }
     //admin has all perms, no more actions are needed
     if ($perm->is_admin()) {
         return $sql_perms;
     }
     $fielditem = $this->colcfg['perm_dbfield_id'];
     $fieldparent = $this->colcfg['perm_dbfield_parent'] != '' ? $this->colcfg['perm_dbfield_parent'] : NULL;
     $tablename = $this->tables[0];
     $clientlang = $this->_getSqlClientLang($this->colcfg['client'], $this->colcfg['lang'], array('client' => 'idclient', 'lang' => 'idlang'));
     $timestamp = $this->_getSqlTimestamp('created', $this->colcfg['timestamp_from'], $this->colcfg['timestamp_to']);
     $freefilter = $this->_getSqlFreefilter($this->colcfg['freefilter']);
     $search = $this->_getSqlSearch($this->colcfg['searchterm'], $this->colcfg['fulltextsearchfileds']);
     $item = sf_api($this->colcfg['model_path'], $this->colcfg['model']);
     $idfield = $item->mapFieldToRow('id', $this->tables[0]);
     $sql = $this->_getPermcheckSql($fielditem, $fieldparent, $tablename, $clientlang, $timestamp, $freefilter, $search);
     if ($sql === FALSE) {
         return $sql_perms;
     }
     $rs = $this->db->Execute($sql);
     if ($rs === FALSE || $rs->EOF) {
         return $sql_perms;
     }
     $positives = array();
     $negatives = array();
     //perms with dependancy
     if ($this->colcfg['perm_dbfield_parent'] != NULL) {
         while (!$rs->EOF) {
             if ($perm->have_perm($this->colcfg['perm_nr'], $this->colcfg['perm_type'], $rs->fields['iditem'], $rs->fields['idparent'])) {
                 array_push($positives, $rs->fields['iditem']);
             } else {
                 array_push($negatives, $rs->fields['iditem']);
             }
             $rs->MoveNext();
         }
     } else {
         while (!$rs->EOF) {
             if ($perm->have_perm($this->colcfg['perm_nr'], $this->colcfg['perm_type'], $rs->fields['iditem'])) {
                 array_push($positives, $rs->fields['iditem']);
             } else {
                 array_push($negatives, $rs->fields['iditem']);
             }
             $rs->MoveNext();
         }
     }
     $rs->Close();
     $count_pos = count($positives);
     $count_neg = count($negatives);
     if ($count_pos == 0 && $count_neg == 0) {
         return $sql_perms;
     } else {
         if ($count_pos < $count_neg && $count_pos > 0) {
             $sql_perms = 'AND ' . $this->colcfg['perm_dbfield_id'] . ' IN (' . implode(',', $positives) . ') ';
         } else {
             if ($count_neg > 0) {
                 $sql_perms = 'AND ' . $this->colcfg['perm_dbfield_id'] . ' NOT IN (' . implode(',', $negatives) . ') ';
             }
         }
     }
     return $sql_perms;
 }
Esempio n. 4
0
 /**
  * Deletes all rights for the item.
  * @return boolean Returns TRUE on success or FALSE on failure.
  */
 public function deleteAllPerms()
 {
     return $this->cfg->perm()->delete_perms($this->getId(), $this->objperm['default']['type'], 0, 0, 0, TRUE);
 }