Exemplo n.º 1
0
function array_sort_by_distance_from($origin, &$ary, &$options = array())
{
    if (!function_exists('compare_distance')) {
        function compare_distance($a, $b)
        {
            if ($a->distance > $b->distance) {
                return 1;
            }
            if ($a->distance < $b->distance) {
                return -1;
            }
            return 0;
        }
    }
    if (array_key_exists('distance_property_name', $options)) {
        $distance_property_name = $options['distance_property_name'];
        array_delete($options, 'distance_property_name');
    } else {
        $distance_property_name = 'distance';
    }
    foreach ($ary as $object) {
        $object->distance = $origin->distance_to($object, $options);
        if (property_exists($object, $distance_property_name)) {
            $object->{$distance_property_name} = $object->distance;
        }
    }
    usort($ary, 'compare_distance');
}
Exemplo n.º 2
0
 public function test_array_delete()
 {
     $ar = array('key1' => 'Foo', 'key2' => 'bar');
     $this->assertEquals('Foo', array_delete($ar, 'key1'));
     $this->assertEquals(array('key2' => 'bar'), $ar);
     $this->assertNull(array_delete($ar, 'not_existing'));
     $this->assertEquals(array('key2' => 'bar'), $ar);
 }
Exemplo n.º 3
0
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $arrButtons = array('copy', 'drag', 'up', 'down', 'delete');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) {
           $this->import('Database');
           switch (\Input::get($strCommand)) {
               case 'copy':
                   $this->varValue = array_duplicate($this->varValue, \Input::get('cid'));
                   break;
               case 'up':
                   $this->varValue = array_move_up($this->varValue, \Input::get('cid'));
                   break;
               case 'down':
                   $this->varValue = array_move_down($this->varValue, \Input::get('cid'));
                   break;
               case 'delete':
                   $this->varValue = array_delete($this->varValue, \Input::get('cid'));
                   break;
           }
           $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
           $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request'))));
       }
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || empty($this->varValue)) {
           $this->varValue = array('');
       }
       // Initialize the tab index
       if (!\Cache::has('tabindex')) {
           \Cache::set('tabindex', 1);
       }
       $tabindex = \Cache::get('tabindex');
       $return = '<ul id="ctrl_' . $this->strId . '" class="tl_listwizard" data-tabindex="' . $tabindex . '">';
       // Add input fields
       for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
           $return .= '
   <li><input type="text" name="' . $this->strId . '[]" class="tl_text" tabindex="' . $tabindex++ . '" value="' . specialchars($this->varValue[$i]) . '"' . $this->getAttributes() . '> ';
           // Add buttons
           foreach ($arrButtons as $button) {
               $class = $button == 'up' || $button == 'down' ? ' class="button-move"' : '';
               if ($button == 'drag') {
                   $return .= \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"');
               } else {
                   $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG']['MSC']['lw_' . $button]) . '" onclick="Backend.listWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml($button . '.gif', $GLOBALS['TL_LANG']['MSC']['lw_' . $button], 'class="tl_listwizard_img"') . '</a> ';
               }
           }
           $return .= '</li>';
       }
       // Store the tab index
       \Cache::set('tabindex', $tabindex);
       return $return . '
 </ul>';
   }
Exemplo n.º 4
0
 public function deletefile($section, $filename)
 {
     if (!isset($this->items[$section])) {
         return false;
     }
     if (!($filename = $this->normfilename($filename))) {
         return false;
     }
     if (false === ($i = array_search($filename, $this->items[$section]['files']))) {
         return false;
     }
     array_delete($this->items[$section]['files'], $i);
     $this->save();
 }
Exemplo n.º 5
0
 protected static function establish_connection($name)
 {
     if (isset(self::$configurations[$name])) {
         $configuration = self::$configurations[$name];
         if (!isset($configuration['dbname'])) {
             $configuration['dbname'] = array_delete('database', $configuration);
         }
         $adapter = array_delete('adapter', $configuration);
         $username = array_delete('username', $configuration);
         $password = array_delete('password', $configuration);
         $connection_string = $adapter . ':';
         $connection_string .= $adapter == 'sqlite' ? $configuration['dbname'] : array_join_assoc('=', ';', $configuration);
         self::$connections[$name] = new PDO($connection_string, $username, $password);
     } else {
         throw new InvalidArgumentException('Database configuration "' . $name . '" does not exist');
     }
 }
Exemplo n.º 6
0
 public function add()
 {
     if (litepublisher::$urlmap->is404) {
         return;
     }
     $url = litepublisher::$urlmap->url;
     $title = litepublisher::$urlmap->context->title;
     foreach ($this->items as $i => $item) {
         if ($url == $item['url']) {
             array_delete($this->items, $i);
             break;
         }
     }
     if (count($this->items) == 10) {
         array_delete($this->items, 9);
     }
     array_insert($this->items, array('url' => $url, 'title' => $title), 0);
     $this->save();
 }
Exemplo n.º 7
0
function array_delete($ary, $key_to_be_deleted)
{
    $new = array();
    if (is_string($key_to_be_deleted)) {
        if (!array_key_exists($key_to_be_deleted, $ary)) {
            return;
        }
        foreach ($ary as $key => $value) {
            if ($key != $key_to_be_deleted) {
                $new[$key] = $value;
            }
        }
        $ary = $new;
    }
    if (is_array($key_to_be_deleted)) {
        foreach ($key_to_be_deleted as $del) {
            $ary = array_delete($ary, $del);
        }
    }
    return $ary;
}
Exemplo n.º 8
0
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $this->import('Database');
       $arrButtons = array('edit', 'copy', 'delete', 'enable', 'drag', 'up', 'down');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) {
           switch (\Input::get($strCommand)) {
               case 'copy':
                   $this->varValue = array_duplicate($this->varValue, \Input::get('cid'));
                   break;
               case 'up':
                   $this->varValue = array_move_up($this->varValue, \Input::get('cid'));
                   break;
               case 'down':
                   $this->varValue = array_move_down($this->varValue, \Input::get('cid'));
                   break;
               case 'delete':
                   $this->varValue = array_delete($this->varValue, \Input::get('cid'));
                   break;
           }
       }
       // Get all modules of the current theme
       $objModules = $this->Database->prepare("SELECT id, name, type FROM tl_module WHERE pid=(SELECT pid FROM " . $this->strTable . " WHERE id=?) ORDER BY name")->execute($this->currentRecord);
       // Add the articles module
       $modules[] = array('id' => 0, 'name' => $GLOBALS['TL_LANG']['MOD']['article'][0], 'type' => 'article');
       if ($objModules->numRows) {
           $modules = array_merge($modules, $objModules->fetchAllAssoc());
       }
       $GLOBALS['TL_LANG']['FMD']['article'] = $GLOBALS['TL_LANG']['MOD']['article'];
       // Add the module type (see #3835)
       foreach ($modules as $k => $v) {
           $v['type'] = $GLOBALS['TL_LANG']['FMD'][$v['type']][0];
           $modules[$k] = $v;
       }
       $objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($this->currentRecord);
       // Show all columns and filter in PageRegular (see #3273)
       $cols = array('header', 'left', 'right', 'main', 'footer');
       $arrSections = trimsplit(',', $objRow->sections);
       // Add custom page sections
       if (!empty($arrSections) && is_array($arrSections)) {
           $cols = array_merge($cols, $arrSections);
       }
       // Get the new value
       if (\Input::post('FORM_SUBMIT') == $this->strTable) {
           $this->varValue = \Input::post($this->strId);
       }
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || !$this->varValue[0]) {
           $this->varValue = array('');
       } else {
           $arrCols = array();
           // Initialize the sorting order
           foreach ($cols as $col) {
               $arrCols[$col] = array();
           }
           foreach ($this->varValue as $v) {
               $arrCols[$v['col']][] = $v;
           }
           $this->varValue = array();
           foreach ($arrCols as $arrCol) {
               $this->varValue = array_merge($this->varValue, $arrCol);
           }
       }
       // Save the value
       if (\Input::get($strCommand) || \Input::post('FORM_SUBMIT') == $this->strTable) {
           $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
           // Reload the page
           if (is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) {
               $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request'))));
           }
       }
       // Initialize the tab index
       if (!\Cache::has('tabindex')) {
           \Cache::set('tabindex', 1);
       }
       $tabindex = \Cache::get('tabindex');
       // Add the label and the return wizard
       $return = '<table id="ctrl_' . $this->strId . '" class="tl_modulewizard">
 <thead>
 <tr>
   <th>' . $GLOBALS['TL_LANG']['MSC']['mw_module'] . '</th>
   <th>' . $GLOBALS['TL_LANG']['MSC']['mw_column'] . '</th>
   <th>&nbsp;</th>
 </tr>
 </thead>
 <tbody class="sortable" data-tabindex="' . $tabindex . '">';
       // Add the input fields
       for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
           $options = '';
           // Add modules
           foreach ($modules as $v) {
               $options .= '<option value="' . specialchars($v['id']) . '"' . static::optionSelected($v['id'], $this->varValue[$i]['mod']) . '>' . $v['name'] . ' [' . $v['type'] . ']</option>';
           }
           $return .= '
 <tr>
   <td><select name="' . $this->strId . '[' . $i . '][mod]" class="tl_select tl_chosen" tabindex="' . $tabindex++ . '" onfocus="Backend.getScrollOffset()" onchange="Backend.updateModuleLink(this)">' . $options . '</select></td>';
           $options = '';
           // Add columns
           foreach ($cols as $v) {
               $options .= '<option value="' . specialchars($v) . '"' . static::optionSelected($v, $this->varValue[$i]['col']) . '>' . (isset($GLOBALS['TL_LANG']['COLS'][$v]) && !is_array($GLOBALS['TL_LANG']['COLS'][$v]) ? $GLOBALS['TL_LANG']['COLS'][$v] : $v) . '</option>';
           }
           $return .= '
   <td><select name="' . $this->strId . '[' . $i . '][col]" class="tl_select_column" tabindex="' . $tabindex++ . '" onfocus="Backend.getScrollOffset()">' . $options . '</select></td>
   <td>';
           // Add buttons
           foreach ($arrButtons as $button) {
               $class = $button == 'up' || $button == 'down' ? ' class="button-move"' : '';
               if ($button == 'edit') {
                   $return .= ' <a href="contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->varValue[$i]['mod'] . '&amp;popup=1&amp;rt=' . REQUEST_TOKEN . '&amp;nb=1" title="' . specialchars($GLOBALS['TL_LANG']['tl_layout']['edit_module']) . '" class="module_link" ' . ($this->varValue[$i]['mod'] > 0 ? '' : ' style="display:none"') . ' onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['tl_layout']['edit_module'])) . '\',\'url\':this.href});return false">' . \Image::getHtml('edit.gif') . '</a>' . \Image::getHtml('edit_.gif', '', 'class="module_image"' . ($this->varValue[$i]['mod'] > 0 ? ' style="display:none"' : ''));
               } elseif ($button == 'drag') {
                   $return .= ' ' . \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"');
               } elseif ($button == 'enable') {
                   $return .= ' ' . \Image::getHtml($this->varValue[$i]['enable'] ? 'visible.gif' : 'invisible.gif', '', 'class="mw_enable" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['mw_enable']) . '"') . '<input name="' . $this->strId . '[' . $i . '][enable]" type="checkbox" class="tl_checkbox mw_enable" value="1" tabindex="' . $tabindex++ . '" onfocus="Backend.getScrollOffset()"' . ($this->varValue[$i]['enable'] ? ' checked' : '') . '>';
               } else {
                   $return .= ' <a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG']['MSC']['mw_' . $button]) . '" onclick="Backend.moduleWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml($button . '.gif', $GLOBALS['TL_LANG']['MSC']['mw_' . $button], 'class="tl_listwizard_img"') . '</a>';
               }
           }
           $return .= '</td>
 </tr>';
       }
       // Store the tab index
       \Cache::set('tabindex', $tabindex);
       return $return . '
 </tbody>
 </table>';
   }
Exemplo n.º 9
0
   /**
    * Generate the widget and return it as string
    * @return string
    */
   public function generate()
   {
       $arrFallback = $this->getFallbackData();
       // Adapt the temporary files
       if (is_array($this->varValue['files']) && !empty($this->varValue['files'])) {
           foreach ($this->varValue['files'] as $v) {
               if (!is_file(TL_ROOT . '/' . $this->getFilePath($v))) {
                   continue;
               }
               $this->varValue[] = array('src' => $v, 'alt' => '', 'desc' => '', 'link' => '', 'translate' => '');
           }
           unset($this->varValue['files']);
       }
       // Merge parent record data
       if ($arrFallback !== false) {
           $blnLanguage = true;
           $this->varValue = Gallery::mergeMediaData($this->varValue, $arrFallback);
       }
       $arrButtons = array('up', 'down', 'delete', 'drag');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) {
           switch (\Input::get($strCommand)) {
               case 'up':
                   $this->varValue = array_move_up($this->varValue, \Input::get('cid'));
                   break;
               case 'down':
                   $this->varValue = array_move_down($this->varValue, \Input::get('cid'));
                   break;
               case 'delete':
                   $this->varValue = array_delete($this->varValue, \Input::get('cid'));
                   break;
           }
           \Database::getInstance()->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
           \Controller::redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request'))));
       }
       $blnIsAjax = \Environment::get('isAjaxRequest');
       $return = '';
       $upload = '';
       if (!$blnIsAjax) {
           $return .= '<div id="ctrl_' . $this->strId . '" class="tl_mediamanager">';
           $extensions = trimsplit(',', $GLOBALS['TL_CONFIG']['validImageTypes']);
           $upload .= '<div id="fineuploader_' . $this->strId . '" class="upload_container"></div>
 <script>
   window.addEvent("domready", function() {
     Isotope.MediaManager.init($("fineuploader_' . $this->strId . '"), "' . $this->strId . '", ' . json_encode($extensions) . ');
   });
 </script>
 <script type="text/template" id="qq-template">
   <div class="qq-uploader-selector qq-uploader">
       <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
           <span>' . $GLOBALS['TL_LANG']['MSC']['mmDrop'] . '</span>
       </div>
       <div class="qq-upload-button-selector qq-upload-button">
           <div class="tl_submit">' . $GLOBALS['TL_LANG']['MSC']['mmUpload'] . '</div>
       </div>
       <span class="qq-drop-processing-selector qq-drop-processing">
           <span>' . $GLOBALS['TL_LANG']['MSC']['mmProcessing'] . '</span>
           <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
       </span>
       <ul class="qq-upload-list-selector qq-upload-list">
           <li>
               <div class="qq-progress-bar-container-selector">
                   <div class="qq-progress-bar-selector qq-progress-bar"></div>
               </div>
               <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
               <span class="qq-edit-filename-icon-selector qq-edit-filename-icon"></span>
               <span class="qq-upload-file-selector qq-upload-file"></span>
               <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
               <span class="qq-upload-size-selector qq-upload-size"></span>
               <span class="qq-upload-status-text-selector qq-upload-status-text"></span>
           </li>
       </ul>
   </div>
 </script>';
       }
       $return .= '<div>';
       if (!is_array($this->varValue) || empty($this->varValue)) {
           return $return . $GLOBALS['TL_LANG']['MSC']['mmNoUploads'] . '</div>' . $upload . (!$blnIsAjax ? '</div>' : '');
       }
       // Add label and return wizard
       $return .= '<table>
 <thead>
 <tr>
   <td class="col_0 col_first">' . $GLOBALS['TL_LANG'][$this->strTable]['mmSrc'] . '</td>
   <td class="col_1">' . $GLOBALS['TL_LANG'][$this->strTable]['mmAlt'] . ' / ' . $GLOBALS['TL_LANG'][$this->strTable]['mmLink'] . '</td>
   <td class="col_2">' . $GLOBALS['TL_LANG'][$this->strTable]['mmDesc'] . '</td>
   <td class="col_3">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslate'] . '</td>
   <td class="col_4 col_last">&nbsp;</td>
 </tr>
 </thead>
 <tbody class="sortable">';
       // Add input fields
       for ($i = 0, $count = count($this->varValue); $i < $count; $i++) {
           $strFile = $this->getFilePath($this->varValue[$i]['src']);
           if (!is_file(TL_ROOT . '/' . $strFile)) {
               continue;
           }
           $objFile = new \File($strFile);
           if ($objFile->isGdImage) {
               $strPreview = \Image::get($strFile, 50, 50, 'box');
           } else {
               $strPreview = 'system/themes/' . $this->getTheme() . '/images/' . $objFile->icon;
           }
           $strTranslateText = $blnLanguage && $this->varValue[$i]['translate'] != 'all' ? ' disabled="disabled"' : '';
           $strTranslateNone = $blnLanguage && $this->varValue[$i]['translate'] == 'none' ? ' disabled="disabled"' : '';
           $return .= '
 <tr>
   <td class="col_0 col_first"><input type="hidden" name="' . $this->strName . '[' . $i . '][src]" value="' . specialchars($this->varValue[$i]['src']) . '"><a href="' . $strFile . '" onclick="Backend.openModalImage({\'width\':' . $objFile->width . ',\'title\':\'' . str_replace("'", "\\'", $GLOBALS['TL_LANG'][$this->strTable]['mmSrc']) . '\',\'url\':\'' . $strFile . '\'});return false"><img src="' . $strPreview . '" alt="' . specialchars($this->varValue[$i]['src']) . '"></a></td>
   <td class="col_1"><input type="text" class="tl_text_2" name="' . $this->strName . '[' . $i . '][alt]" value="' . specialchars($this->varValue[$i]['alt'], true) . '"' . $strTranslateNone . '><br><input type="text" class="tl_text_2" name="' . $this->strName . '[' . $i . '][link]" value="' . specialchars($this->varValue[$i]['link'], true) . '"' . $strTranslateText . '></td>
   <td class="col_2"><textarea name="' . $this->strName . '[' . $i . '][desc]" cols="40" rows="3" class="tl_textarea"' . $strTranslateNone . ' >' . specialchars($this->varValue[$i]['desc']) . '</textarea></td>
   <td class="col_3">
       ' . ($blnLanguage ? '<input type="hidden" name="' . $this->strName . '[' . $i . '][translate]" value="' . $this->varValue[$i]['translate'] . '">' : '') . '
       <fieldset class="radio_container">
           <span>
               <input id="' . $this->strName . '_' . $i . '_translate_none" name="' . $this->strName . '[' . $i . '][translate]" type="radio" class="tl_radio" value="none"' . $this->optionChecked('none', $this->varValue[$i]['translate']) . ($blnLanguage ? ' disabled="disabled"' : '') . '>
               <label for="' . $this->strName . '_' . $i . '_translate_none" title="' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateNone'][1] . '">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateNone'][0] . '</label></span>
           <span>
               <input id="' . $this->strName . '_' . $i . '_translate_text" name="' . $this->strName . '[' . $i . '][translate]" type="radio" class="tl_radio" value="text"' . $this->optionChecked('text', $this->varValue[$i]['translate']) . ($blnLanguage ? ' disabled="disabled"' : '') . '>
               <label for="' . $this->strName . '_' . $i . '_translate_text" title="' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateText'][1] . '">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateText'][0] . '</label></span>
           <span>
               <input id="' . $this->strName . '_' . $i . '_translate_all" name="' . $this->strName . '[' . $i . '][translate]" type="radio" class="tl_radio" value="all"' . $this->optionChecked('all', $this->varValue[$i]['translate']) . ($blnLanguage ? ' disabled="disabled"' : '') . '>
               <label for="' . $this->strName . '_' . $i . '_translate_all" title="' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateAll'][1] . '">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateAll'][0] . '</label></span>
       </fieldset>
   </td>
   <td class="col_4 col_last">';
           // Add buttons
           foreach ($arrButtons as $button) {
               if ($button == 'delete' && $blnLanguage && $this->varValue[$i]['translate'] != 'all') {
                   continue;
               }
               $class = $button == 'up' || $button == 'down' ? ' class="button-move"' : '';
               if ($button == 'drag') {
                   $return .= \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"');
               } else {
                   $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button]) . '" onclick="Isotope.MediaManager.act(this, \'' . $button . '\',  \'ctrl_' . $this->strId . '\'); return false;">' . \Image::getHtml($button . '.gif', $GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button], 'class="tl_listwizard_img"') . '</a> ';
               }
           }
           $return .= '</td>
 </tr>';
       }
       return $return . '
 </tbody>
 </table>
 </div>' . $upload . (!$blnIsAjax ? '</div>' : '');
   }
Exemplo n.º 10
0
function include_all($x)
{
    extract($x);
    #add a few extra variables that will be usefull in the output;
    #x = array('elements'=>, 'element_info'=>, 'user_id'=>, 'db'=>)
    #Example: $data = include_all(compact('elements', 'element_info', 'user_id', 'db'));
    #when there is no resource_class_id, find it from the project where instance was created. WILL ASSUME THAT RESOURCE_CLASS_ID FILLED OUT IS A REQUIREMENT FOR ALL S3DB THAT SHARE RULES
    if ($_REQUEST['project_id'] == '') {
        $project_id = $element_info['project_id'];
    } else {
        $project_id = $_REQUEST['project_id'];
    }
    if (!$model) {
        $model = 'nsy';
    }
    if ($letter == '') {
        $letter = strtoupper(substr($elements, 0, 1));
    }
    if (is_array($GLOBALS['s3map'][$GLOBALS['plurals'][$GLOBALS['s3codes'][$letter]]])) {
        foreach ($GLOBALS['s3map'][$GLOBALS['plurals'][$GLOBALS['s3codes'][$letter]]] as $replace => $with) {
            $element_info[$replace] = $element_info[$with];
        }
    }
    #if element is a class, return the class id
    if ($letter == 'D') {
        $element_info['acl'] = $user_id == '1' ? '222' : (user_is_admin($user_id, $db) ? '212' : (user_is_public($user_id, $db) ? '210' : '211'));
        $element_info['created_by'] = $user_id;
        $element_info['description'] = $GLOBALS['s3db_info']['server']['site_intro'];
        $element_info['name'] = $GLOBALS['s3db_info']['server']['site_title'];
        if ($element_info['deployment_id'] == $GLOBALS['s3db_info']['deployment']['Did']) {
            $element_info['self'] = 1;
        }
    }
    if ($letter == 'G') {
        #echo '<pre>';print_r($x);exit;
        $e = 'groups';
        #$element_info['group_id'] = $element_info['account_id'];
        #$element_info['groupname'] = $element_info['account_uname'];
        #$element_info['acl'] = groupAcl($element_info, $user_id, $db);
        $uid_info = uid($element_info['account_id']);
        $element_info['deployment_id'] = ereg_replace('^D', '', $uid_info['Did']);
        $strictuid = 1;
        $strictsharedwith = 1;
        $uid = 'G' . $element_info['group_id'];
        $shared_with = 'U' . $user_id;
        #$element_info['acl'] = permissionOnResource(compact('user_id', 'shared_with', 'db', 'uid','key','strictsharedwith','strictuid'));
        $element_info['acl'] = groupAcl($element_info, $user_id, $db, $timer);
        if ($timer) {
            $timer->setMarker('Included resource information for ' . $letter);
        }
        #echo '<pre>';print_r($element_info);exit;
    }
    if ($letter == 'U') {
        if ($element_info['account_addr_id'] != '') {
            $sql = "select * from s3db_addr where addr_id = '" . $element_info['account_addr_id'] . "'";
            $fields = array('addr1', 'addr2', 'city', 'state', 'postal_code', 'country');
            $db->query($sql);
            while ($db->next_record()) {
                for ($i = 0; $i < count($fields); $i++) {
                    $element_info[$fields[$i]] = $db->f($fields[$i]);
                }
            }
            $element_info = array_delete($element_info, 'account_addr_id');
        }
        $element_info['user_id'] = $element_info['account_id'];
        $element_info['username'] = $element_info['account_uname'];
        $element_info['login'] = $element_info['account_lid'];
        $element_info['address'] = $element_info['addr1'];
        $uid_info = uid($element_info['account_id']);
        $element_info['deployment_id'] = ereg_replace('^D', '', $uid_info['Did']);
        if ($user_id != '1' && $element_info['created_by'] != $user_id && $element_info['account_id'] != $user_id) {
            #if user is not seing himself and user is not admin and user was not the creator of element, then hide address, email, phone, etc.
            $keys2Remove = array('account_email' => '', 'account_phone' => '', 'addr1' => '', 'addr2' => '', 'city' => '', 'state' => '', 'postal_code' => '', 'country' => '');
            if (is_array($element_info)) {
                $element_info = array_diff_key($element_info, $keys2Remove);
            }
        }
        if ($user_id != '1' && $element_info['created_by'] != $user_id && $user_id != $element_info['account_id']) {
            if (is_array($element_info)) {
                $element_info = array_diff_key($element_info, array('account_type' => '', 'account_status' => ''));
            }
        } else {
            //if this user has been created with a filter, what is that filter
            $permission_info = array('uid' => 'U' . $element_info['created_by'], 'shared_with' => 'U' . $element_info['account_id']);
            $hp = has_permission($permission_info, $db);
            if ($hp) {
                $element_info['filter'] = $hp;
            }
        }
        if (is_array($element_info)) {
            $element_info = array_diff_key($element_info, array('account_pwd' => ''));
        }
        $user_id_who_asks = $user_id;
        $uid = 'U' . $element_info['user_id'];
        $shared_with = $user_id_who_asks;
        $strictuid = 1;
        $strictsharedwith = 1;
        $onPermissions = compact('user_id', 'shared_with', 'db', 'uid', 'key', 'strictsharedwith', 'strictuid');
        if ($element_info['acl'] == '') {
            $element_info['acl'] = userAcl(compact('key', 'element_info', 'user_id_who_asks', 'db'));
        }
    }
    if ($letter == 'P') {
        $element_info['name'] = $element_info['project_name'];
        $element_info['description'] = $element_info['project_description'];
        $id = 'P' . $element_info['project_id'];
        $uid = 'P' . $element_info['project_id'];
    }
    if ($letter == 'C') {
        $element_info['class_id'] = $element_info['resource_id'];
        $element_info['collection_id'] = $element_info['class_id'];
        $element_info['name'] = $element_info['entity'];
        $element_info['description'] = $element_info['notes'];
        #project_id to search for rule_id will be the same from the class
        $uid = 'C' . $element_info['resource_id'];
    }
    #if element is a rule, return the class_id of the subject. If the object is a class, return the object_id... to discuss with jonas
    if ($letter == 'R') {
        $uid = 'R' . $element_info['rule_id'];
    }
    #if this is an instance, return the class_id => ASSUMING THAT EVERY S3DB THAT HAS SHARED RULES HAS RESOURCECLASSID IN INSTANCE.
    if ($letter == 'I') {
        if ($element_info['resource_class_id'] != '') {
            $element_info['class_id'] = $element_info['resource_class_id'];
        }
        $element_info['instance_id'] = $element_info['resource_id'];
        $element_info['item_id'] = $element_info['instance_id'];
        $element_info['collection_id'] = $element_info['class_id'];
        $instance_id = $element_info['instance_id'];
        $uid = 'I' . $element_info['instance_id'];
    }
    if ($letter == 'S') {
        $uid = 'S' . $element_info['statement_id'];
        $info[$id] = $element_info;
        $statement_id = $element_info['statement_id'];
        $element_info['instance_id'] = $element_info['resource_id'];
        $element_info['item_id'] = $element_info['instance_id'];
        $element_info['instance_notes'] = $info['I' . $element_info['instance_id']]['notes'];
        if ($info['R' . $element_info['rule_id']] == '') {
            $info['R' . $element_info['rule_id']] = s3info('rule', $element_info['rule_id'], $db);
        }
        $element_info['object_notes'] = notes($element_info['value'], $db);
        $element_info['project_folder'] = $element_info['value'];
        $element_info = include_fileLinks($element_info, $db);
        $element_info['subject'] = $info['R' . $element_info['rule_id']]['subject'];
        $element_info['verb'] = $info['R' . $element_info['rule_id']]['verb'];
        $element_info['object'] = $info['R' . $element_info['rule_id']]['object'];
        $element_info['subject_id'] = $info['R' . $element_info['rule_id']]['subject_id'];
        $element_info['verb_id'] = $info['R' . $element_info['rule_id']]['verb_id'];
        $element_info['object_id'] = $info['R' . $element_info['rule_id']]['object_id'];
    }
    $strictuid = 1;
    $strictsharedwith = 1;
    $shared_with = 'U' . $user_id;
    $toFindInfo = $element_info;
    $onPermissions = compact('user_id', 'shared_with', 'db', 'uid', 'key', 'strictsharedwith', 'strictuid', 'timer', 'toFindInfo');
    if ($element_info['acl'] == '') {
        $element_info['acl'] = permission4Resource($onPermissions);
    }
    $element_info['permission_level'] = $element_info['acl'];
    if (!$element_info['effective_permission']) {
        $element_info['effective_permission'] = $element_info['acl'];
    }
    if (!$element_info['assigned_permission']) {
        $pp = array('uid' => $uid, 'shared_with' => $shared_with);
        $tmp = has_permission($pp, $db);
        if ($tmp) {
            $element_info['assigned_permission'] = $tmp;
        } else {
            $element_info['assigned_permission'] = '---';
        }
    }
    #Define if ser can view or not view data. View is the first number in the 3d code.
    $permission2user = permissionModelComp($element_info['permission_level']);
    ##According to the model, change the values of assigned_permission from prevous versions
    $element_info['assigned_permission'] = str_replace(array('0', '1', '2'), str_split($model), $element_info['assigned_permission']);
    $isOwner = $element_info['created_by'] == $user_id;
    $element_info['view'] = allowed($permission2user, 0, $isOwner, $state = 3, $model);
    $element_info['change'] = allowed($permission2user, 1, $isOwner, $state = 3, $model);
    $element_info['propagate'] = allowed($permission2user, 2, $isOwner, $state = 3, $model);
    #create the element "delete", in case it is eventually created...For now it is the same as change
    $element_info['delete'] = $element_info['change'];
    $element_info['delete_data'] = $element_info['add_data'];
    $element_info['add_data'] = $element_info['propagate'];
    return $element_info;
}
Exemplo n.º 11
0
    /**
     * Generate the widget and return it as string
     * @return string
     */
    public function generate()
    {
        $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/isotope/html/backend.js';
        $this->import('Database');
        //allows us to set which buttons can be enabled for this widget.
        /*foreach($this->enabledFunctions as $v)
        		{
        			$arrButtons[] = $v;
        		}*/
        $strCommand = 'cmd_' . $this->strField;
        // Change the order
        if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
            switch ($this->Input->get($strCommand)) {
                case 'copy':
                    $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid'));
                    break;
                case 'up':
                    $this->varValue = array_move_up($this->varValue, $this->Input->get('cid'));
                    break;
                case 'down':
                    $this->varValue = array_move_down($this->varValue, $this->Input->get('cid'));
                    break;
                case 'delete':
                    $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                    break;
            }
        }
        $objTaxClasses = $this->Database->execute("SELECT id, name FROM tl_iso_tax_class");
        if ($objTaxClasses->numRows) {
            $arrTaxClasses = $objTaxClasses->fetchAllAssoc();
        }
        if (!is_array($arrTaxClasses) || !count($arrTaxClasses)) {
            $arrTaxClasses = array('');
        }
        // Get new value
        if ($this->Input->post('FORM_SUBMIT') == $this->strTable) {
            $varValue = $this->Input->post($this->strId);
        }
        // Make sure there is at least an empty array
        if (!is_array($this->varValue) || !$this->varValue[0]) {
            //$this->varValue = array('');
        } else {
            /*foreach($this->varValue as $v)
            			{
            
            
            			}*/
        }
        // Save the value
        if ($this->Input->get($strCommand) || $this->Input->post('FORM_SUBMIT') == $this->strTable) {
            $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
            // Reload the page
            if (is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
                $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
            }
        }
        // Add label and return wizard
        $return .= '<table class="tl_optionwizard" id="ctrl_' . $this->strId . '">
  <thead>';
        if (is_array($this->varValue) && count($this->varValue)) {
            $return .= '
    <tr>
      <th><strong>' . $GLOBALS['TL_LANG'][$this->strTable]['opLabel'] . '</strong></th>
      <th><strong>' . $GLOBALS['TL_LANG'][$this->strTable]['opPrice'] . '</strong></th>
      <th><strong>' . $GLOBALS['TL_LANG'][$this->strTable]['opTaxClass'] . '</strong></th>
      <th>&nbsp;</th>
    </tr>
  </thead>
  <tbody>';
            // Add rows
            for ($i = 0; $i < count($this->varValue); $i++) {
                $arrRow = array();
                $arrRow = $this->varValue[$i];
                $blnEditable = false;
                if (is_array($arrRow)) {
                    $blnEditable = true;
                } else {
                    continue;
                }
                $return .= '<tr>';
                $return .= '	<td>' . $this->varValue[$i]['label'] . '<input type="hidden" name="' . $this->strId . '[' . $i . '][label]" id="' . $this->strId . '_label_' . $i . '" value="' . $this->varValue[$i]['label'] . '"></td>';
                $return .= '	<td>' . ($blnEditable ? '<input type="text" name="' . $this->strId . '[' . $i . '][total_price]" id="' . $this->strId . '_total_price_' . $i . '" class="tl_text_3" value="' . specialchars(round($this->varValue[$i]['total_price'], 2)) . '">' : round($this->varValue[$i]['total_price'], 2)) . '</td>';
                $options = '';
                $options = '<option value=""' . $this->optionSelected(NULL, $this->varValue[$i]['tax_class']) . '>-</option>';
                // Add Tax Classes
                foreach ($arrTaxClasses as $v) {
                    $options .= '<option value="' . specialchars($v['id']) . '"' . $this->optionSelected($v['id'], $this->varValue[$i]['tax_class']) . '>' . $v['name'] . '</option>';
                    if ($v['id'] == $this->varValue[$i]['tax_class']) {
                        $strTaxLabel = $v['name'];
                    }
                }
                $return .= '
      <td>' . ($blnEditable ? '<select name="' . $this->strId . '[' . $i . '][tax_class]" class="tl_select_2" onfocus="Backend.getScrollOffset();">' . $options . '</select>' : $strTaxLabel) . '</td>';
                $return .= '<td>';
                if (is_array($arrButtons)) {
                    foreach ($arrButtons as $button) {
                        $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button]) . '" onclick="Isotope.surchargeWizard(this, \'' . $button . '\',  \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button], 'class="tl_listwizard_img"') . '</a> ';
                    }
                } else {
                    $return .= '&nbsp;';
                }
                $return .= '
      </td>
	</tr>';
            }
        } else {
            $return .= '
    <tr>
      <th>&nbsp;</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>' . $GLOBALS['TL_LANG']['MSC']['noSurcharges'] . '</td>
    </tr>';
        }
        return $return . '
  </tbody>
</table>';
    }
Exemplo n.º 12
0
function selectQuery($D)
{
    global $timer;
    extract($D);
    if ($s3ql['from'] == 'deployment') {
        $data[0] = array('mothership' => $GLOBALS['s3db_info']['deployment']['mothership'], 'deployment_id' => $GLOBALS['s3db_info']['deployment']['Did'], 'self' => '1', 'description' => $GLOBALS['s3db_info']['server']['site_intro'], 'url' => S3DB_URI_BASE, 'message' => 'Successfully connected to deployment ' . $GLOBALS['s3db_info']['deployment']['Did'] . '. Please provice a key to query the data (for example: ' . ($_SERVER['https'] == 'on' ? 'https://' : 'http://') . $def . S3DB_URI_BASE . '/URI.php?key=xxxxxxxx. For syntax specification and instructions refer to http://s3db.org/');
        #return $data;
    }
    #echo '<pre>';print_r($s3ql);
    if (in_array($s3ql['from'], array_keys($GLOBALS['plurals']))) {
        $s3ql['from'] = $GLOBALS['plurals'][$s3ql['from']];
    }
    #echo '<pre>';print_r($s3ql);exit;
    if ($s3ql['from'] == 'classes') {
        $s3ql['from'] = 'collections';
    }
    if ($s3ql['from'] == 'instances') {
        $s3ql['from'] = 'items';
    }
    if ($s3ql['from'] == 'keys' && $_SESSION['db'] == '') {
        return formatReturn($GLOBALS['error_codes']['not_a_query'], 'Access keys cannot be queried in the API.', $s3ql['format'], '');
        exit;
    }
    if (eregi('^t', $s3ql['shared'])) {
        $shared = true;
        #shared being set to true will tell s3ql that he should not only retrieved uid native to the upstream resource being queried, but those that propagate toward it
        $s3ql = array_delete($s3ql, 'shared');
    }
    if ($s3ql['from'] == 'permission' && $user_id != 1) {
        return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User cannot query permissions.', $s3ql['format'], '');
        exit;
    }
    if (eregi('^t', $s3ql['shared'])) {
        $shared = true;
        #shared being set to true will tell s3ql that he should not only retrieved uid native to the upstream resource being queried, but those that propagate toward it
        $s3ql = array_delete($s3ql, 'shared');
    }
    if (eregi('complete', $s3ql['display'])) {
        $complete = true;
        #complete will tell s3ql that dictionary terms should be added to the output
        $s3ql = array_delete($s3ql, 'display');
    }
    $target = $s3ql['from'];
    $letter = strtoupper(substr($s3ql['from'], 0, 1));
    $table = strval($target);
    $element = $target;
    $cols = $GLOBALS['dbstruct'][$target];
    $element_id = $s3ql['where'][$GLOBALS['s3ids'][$element]];
    if ($table != '' && !in_array($table, array_keys($GLOBALS['dbstruct']))) {
        return formatReturn($GLOBALS['error_codes']['not_a_query'], 'Not a valid query.', '', $s3ql['format']);
    }
    #manage data in select
    #echo '<pre>';print_r($s3ql);
    #array_keys contains the things to replace and array_values the replacements
    if ($s3ql['select'] != '' && $s3ql['select'] != '*') {
        $s3ql_out = ereg_replace(' ', '', $s3ql['select']);
        #take out all the spaces
        $returnFields = explode(',', $s3ql_out);
        if (!ereg($GLOBALS['s3ids'][$element], $s3ql['select'])) {
            if (ereg('count|max|min', $s3ql['select'])) {
                $SQLfun = ereg_replace("\\(.*\\)", "", $select);
                $SQLfun = ereg_replace("count as count", "count", $SQLfun);
                $s3ql['select'] = '*';
            } else {
                $s3ql['select'] .= ',' . $GLOBALS['s3ids'][$element];
            }
        }
        ##Because of the new code, will also have to add the parent ids to the query
        #$parents = $GLOBALS['inherit'][$GLOBALS['s3ids'][$element]];
        $parents = $GLOBALS['inherit'][$GLOBALS['COREids'][$GLOBALS['singulars'][$element]]];
        ##duuuhhh
        if (is_array($parents)) {
            foreach ($parents as $p) {
                if (!in_array($p, $returnFields)) {
                    $s3ql['select'] .= ',' . str_replace($toreplace, $replacements, $p);
                }
            }
        }
    } else {
        $s3ql['select'] = '*';
    }
    #echo $s3ql['select'];exit;
    #echo '<pre>';print_r($s3ql);exit;
    $toreplace = array_keys($GLOBALS['s3map'][$target]);
    $replacements = array_values($GLOBALS['s3map'][$target]);
    #to replace query str with replacements, remove the spaces and explode by commas
    $select = explode(',', str_replace(' ', '', $s3ql['select']));
    foreach ($select as $s_key => $str_select) {
        if (in_array($str_select, $toreplace)) {
            $select[$s_key] = $replacements[array_search($str_select, $toreplace)];
        }
    }
    #echo '<pre>';print_r($select);exit;
    $s3ql['select'] = implode(',', array_unique($select));
    #$s3ql['select'] = str_replace($toreplace, $replacements, $s3ql['select']);
    #echo '<pre>';print_r($s3ql['select']);
    $select = urldecode($s3ql['select']);
    $select = eregi_replace('uid', $GLOBALS['s3ids'][$element] . ' as uid', $select);
    $select = eregi_replace('uri', $GLOBALS['s3ids'][$element] . ' as uri', $select);
    $select = eregi_replace('(,).*permissionOnResource', '', $select);
    #echo $P['out'].$P['SQLfun'];
    if ($select == $SQLfun) {
        $SQLfun = '';
    }
    #$s3ql_where_keys = str_replace(array('item_id', 'collection_id'), array('instance_id', 'class_id'), array_keys($s3ql['where']));
    #$s3ql['where'] = array_combine($s3ql_where_keys, $s3ql['where']);
    #transofrmt s3ql and get the return Fields
    $tranformed = S3QLselectTransform(compact('s3ql', 'db', 'user_id'));
    extract($tranformed);
    #anything that is queried must also go come out in the select
    if ($s3ql['where'] && $select != '*') {
        foreach ($s3ql['where'] as $more_outputs => $more_value) {
            if (!substr($select, $more_outputs)) {
                $select .= "," . str_replace($toreplace, $replacements, $more_outputs);
            }
        }
    }
    ##for statements, select must find file_name a well so that it is transofmred into a link
    if ($letter == 'S' && !ereg('file_name', $select)) {
        $select .= ',file_name';
    }
    $s3ql['select'] = $select;
    if ($timer) {
        $timer->setMarker('queryInterpreted');
    }
    #If there is any sort of S3 UID in the query, check its score when compared to the from
    $score = array('D' => '7', 'G' => '6', 'U' => '5', 'P' => '4', 'C' => '3', 'R' => '3', 'I' => '2', 'S' => '1');
    $fromScore = $score[strtoupper(substr($target, 0, 1))];
    $s3Ids = array_merge($GLOBALS['COREids'], array('rulelog' => 'rule_id', 'statementlog' => 'statement_id'));
    #echo '<pre>';print_r($s3ql);
    $shared_with_query = array();
    foreach ($s3Ids as $COREelement => $COREelement_id) {
        if ($s3ql['where'][$COREelement_id] != '' && !ereg('^~|regexp', $s3ql['where'][$COREelement_id])) {
            $id_name = $COREelement_id;
            $id_letter = strtoupper(substr($id_name, 0, 1));
            $whereScore[strtoupper(substr($id_name, 0, 1)) . $s3ql['where'][$COREelement_id]] = $score[strtoupper(substr($id_name, 0, 1))];
            #when idNameScore is < $fromScore, then we know: we are trying to query all resources that can view another particular resource (for example,all users that can view project x
            #echo $id_name;exit;
            $uid = strtoupper(substr($COREelement, 0, 1)) . $s3ql['where'][$COREelement_id];
            $uid_info = uid($uid);
            #Use URIinfo to find all data about this resource
            $element_info = URIinfo($uid, $user_id, $key, $db, $timer);
            $WhereInfo[$uid_info['uid']] = $element_info;
            if (!is_array($element_info)) {
                return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], $uid . ' does not exist', $s3ql['format'], '');
                exit;
            } elseif ($id_letter != strtoupper(substr($element, 0, 1))) {
                ##Shared_with is any UID that can eb shared with any of the elements being requested (for example, Collection_id is shared_with Project, but Project_id is not shared  with Project
                array_push($shared_with_query, $uid);
                #do permissions on this uid propagate?
                #echo '<pre>';print_r($whereScore);exit;
            } else {
                $self_id = $s3ql['where'][$COREelement_id];
                if (!$element_info['view']) {
                    return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission on ' . $uid, $s3ql['format'], '');
                    exit;
                }
            }
        }
    }
    #echo '<pre>';print_r($WhereInfo);exit;
    if ($self_id != '') {
        $data[0] = $element_info;
        if (ereg('^(U|G)$', $letter) && count($WhereInfo) == 2) {
            $whereId = array_diff(array_keys($WhereInfo), array($letter . $self_id));
            $D = array('shared_with' => $letter . $self_id, 'uid' => $whereId[0], 'strictsharedwith' => 1, 'strictuid' => 1, 'db' => $db, 'user_id' => $user_id, 'stream' => 'upstream', 'timer' => $timer);
            ##Look for shared_with in uid instead of uid in shared_with
            #echo 'ola';exit;
            #$data[0]['permissionOnResource']=permission4Resource($D);
            $p = array('shared_with' => $letter . $self_id, 'uid' => $whereId[0]);
            $hasP = has_permission($p, $db);
            $effective_permission_resource = permission4resource(array('user_id' => $self_id, 'shared_with' => $letter . $self_id, 'db' => $db, 'uid' => $whereId[0], 'strictsharedwith' => 1, 'strictuid' => 1, 'timer' => $timer, 'toFindInfo' => $WhereInfo[$whereId[0]]));
            if ($hasP || $effective_permission_resource != '') {
                $data[0]['permissionOnResource'] = $effective_permission_resource;
                $data[0]['assigned_permissionOnEntity'] = $hasP != "" ? $hasP : '---';
                $data[0]['effective_permissionOnEntity'] = $effective_permission_resource;
            } else {
                return array();
            }
        }
    } else {
        #echo 'ola';exit;
        #start building the query:
        $user_query = "select " . $select . " from s3db_" . $GLOBALS['s3tables'][$table];
        if (!user_is_admin($user_id, $db)) {
            $cols = array_diff($cols, array('account_pwd', 'account_phone', 'account_email', 'project_folder'));
        }
        #remove a few cols from query
        if ($timer) {
            $timer->setMarker('user is admin check');
        }
        #echo $user_id;exit;
        ##	echo $user_query;exit;
        #now add some constrains necessary due to the type of resource
        if (!(user_is_admin($user_id, $db) && $s3ql['where']['status'] == 'I')) {
            if (ereg('projects|classes|instances|rules|statements', $target)) {
                $status = "status!='I' and ";
            }
        }
        $user_query_const .= " where " . $status . $GLOBALS['s3ids'][$target] . "!='0'";
        ###
        #Filter query according to the element being requested
        $user_query_const .= filterByElement($s3ql, $user_id, $db);
        if ($user_query_const) {
            $user_query .= $user_query_const;
        } else {
            exit;
        }
        if ($timer) {
            $timer->setMarker('query filter');
        }
        if ($shared && !empty($shared_with_query) && strtoupper(substr($target, 0, 1)) != 'U') {
            #the "shared with" are the upstream resources being queried. These may or not be in  the permissions table (if the are remote). This basically finds not only elements that were created within a certain uid (for example Ix of Cx), but those that were later shared with that uid (for example Iy created within Cy but later shared with Iy)
            $uidQuery = simpleQueryUID($shared_with_query, $element, $db);
            if ($uidQuery) {
                extract($uidQuery);
                if (!ereg('G', $letter)) {
                    #query groups has a special syntax, it is already included in the query
                    $user_query .= $finalUID;
                }
                ##IS IT INCREASING THE QUERY TIME ABSURDELLY?
            }
            #else { #Go on with the regular query
            #		return formatReturn($GLOBALS['error_codes']['no_results'], 'Your query on '.$target.' did not return any results', $format,'');
            #	}
            if ($timer) {
                $timer->setMarker('Query to find shared UID');
            }
        }
        #now constrainthe query to resources that user cann access. Check for inherited permissions and direct permissions. Project is connected to deployment, rule and class to project, and so on. (see S3DB third report for the schema)
        #Fetch the cols of what is to be returned. Check for SqL functions. This will only affect the output
        if ($s3ql['select'] != '') {
            $out = urldecode($s3ql['select']);
            $SQLfun = ereg_replace("\\(.*\\)", "", $out);
            $SQLfun = ereg_replace("count as count", "count", $SQLfun);
            $P['out'] . $P['SQLfun'];
            if ($out == $SQLfun) {
                $SQLfun = '';
            } else {
                $extracol = $out;
            }
        }
        #echo $SQLfun;
        #Extract from the s3ql the value that are part of the syntax and assume the rest are the SQL extras (limit, creted_by, etc)
        $syntax = array('key', 'select', 'from', 'where', 'format');
        foreach ($s3ql as $i => $value) {
            if (!in_array($i, $syntax) && $value != '') {
                $SQLextra[$i] = ' ' . ereg_replace('_', ' ', $i) . ' ' . $value;
            }
        }
        #echo '<pre>';print_r($SQLextra);exit;
        #if there is orderby, move to the beginnign of the array
        if ($SQLextra['order_by'] != '') {
            $SQLextra = array_merge(array('order_by' => $SQLextra['order_by']), $SQLextra);
        }
        if (is_array($SQLextra)) {
            foreach ($SQLextra as $key => $value) {
                $query_extra .= $value;
            }
        }
        #Put in $P the values of what is queried, add to cols, if not already there, whatever is queried. Check if there are regular expressions anywhere. equalit will be replace by the regular expression
        $cols = $GLOBALS['dbstruct'][$table];
        foreach ($cols as $col) {
            if ($s3ql['where'][$col] != '') {
                if (!in_array($col, $GLOBALS['COREids']) && $col != $GLOBALS['COREids'][$element]) {
                    $user_query_fields .= ' and ' . $col . '  ' . parse_regexp($s3ql['where'][$col]);
                }
                $P[$col] = parse_regexp($s3ql['where'][$col]);
            }
        }
        #when the default query is performed, that is, not shared ids are requested, the query is faster is core_id are added
        if (!$shared) {
            if (is_array($s3ql['where']) && !empty($s3ql['where'])) {
                foreach ($s3ql['where'] as $q_field => $q_value) {
                    if (in_array($q_field, $GLOBALS['COREids']) || $q_field == $GLOBALS['COREids'][$element]) {
                        $sql_col = str_replace($toreplace, $replacements, $q_field);
                        if (!ereg('U|G', $letter)) {
                            ## Users and groups do not have the reousrce in the users table
                            $user_query_fields .= ' and ' . $sql_col . ' ' . parse_regexp($q_value);
                        } else {
                            #Because users queries do not include the parent_id in the talbe itself, they will involve a query in perm table
                            #$u_uid=letter($q_field).$q_value;
                        }
                    }
                }
            }
        }
        #glue them together.
        $user_query .= $user_query_fields . $query_extra;
        if ($timer) {
            $timer->setMarker('done building query');
        }
        ###Finally perform the query on whatever table is specified
        #$user_query = "select * from s3db_resource where resource_class_id = '389';";
        #if($_REQUEST['su3d']){
        #echo $user_query;
        #$timer->display();
        #exit;
        #}
        ##run it
        #complete query on LOCAL resources
        $db->query($user_query, __LINE__, __FILE__);
        $dbdata = get_object_vars($db);
        if ($timer) {
            $timer->setMarker('done with query');
        }
        if ($dbdata['Errno'] != '0') {
            return formatReturn($GLOBALS['error_codes']['something_went_wrong'], $dbdata['Error'], $format, '');
        }
        #put it in a nice structured variable
        $cols = $GLOBALS['dbstruct'][$target];
        if (is_array($returnFields) && $extracol == '') {
            $cols = array_unique(array_merge($cols, $returnFields));
        }
        #echo '<pre>';print_r($cols);
        while ($db->next_record()) {
            #echo '<pre>';print_r($db);
            $resultStr .= "\$data[] = Array(";
            if ($extracol != '') {
                $resultStr .= "'" . $extracol . "'=>'" . $db->f($SQLfun) . "',";
            }
            foreach ($cols as $col) {
                $resultStr .= "'" . $col . "'=>'" . addslashes($db->f($col)) . "'";
                if ($col != end($cols)) {
                    $resultStr .= ",";
                }
                if ($col == $GLOBALS['s3ids'][$target]) {
                    $retrieved['ids_str'] .= $retrieved['ids_str'] == '' ? $db->f($col) : '|' . $db->f($col);
                }
            }
            $resultStr .= ");";
        }
        #echo $resultStr;
        #evaluate the long string
        eval($resultStr);
        if (is_array($data)) {
            $data = array_filter($data);
        }
        if ($timer) {
            $timer->setMarker('query results captured');
        }
        #more often than not, a query is made that retrieves all rules/collection data; this data can be reused for permission migration
        if ($user_query_fields == "" && $SQLextra == "") {
            $all_data[letter($target)] = $data;
        }
        #BEFORE outputting data, are there any remote resources where the user is allowed?
        $ucode = strtoupper(substr($element, 0, 1));
        $ucode_and_id = $ucode . $element_id;
        ##Added ability to search locally on april 15 2008 to optimize queries
        ###Added ability to seeek permissions from file on jan 12 2009 to speed permissiosn query
        if (!ereg('users|groups|projects|keys|rulelog|statementlog|permission', $s3ql['from']) && !ereg('true|1', $s3ql['where']['local'])) {
            #REMOTE USERS< GROUPS< PROJECTS ARE INSERTED INTO DEPLOYMENT,M NO NEED TO FIND THEM AGAIN
            ##Added ability to search locally on april 15 to optimize queries
            ###Added ability to seeek permissions from file on jan 12 2009 to speed permissiosn query
            list($remoteIDS, $local_not_native) = remotePermissions(compact('s3ql', 'self_id', 'uidQuery', 'permissionsQuery', 'user_id', 'db', 'timer', 'shared_with_query', 'user_self_query', 'letter'));
            if ($timer) {
                $timer->setMarker('remote permisions queried');
            }
            ##NOTE: Local_not_native data need to be retrieve as well
            if (is_array($remoteIDS) && !empty($remoteIDS)) {
                foreach ($remoteIDS as $rem_id) {
                    #$rem_uid = substr($rem_id['uid'],1,strlen($rem_id['uid']));
                    $rem_uid = $rem_id['uid'];
                    $rem_resource_data = URIinfo($rem_uid, $user_id, $s3ql['key'], $db);
                    #echo '<pre>';print_r($rem_resource_data);exit;
                    if (is_array($rem_resource_data)) {
                        $rem_resource_data['shared_with'] = $rem_id['shared_with'];
                        $rem_resource_data['uid'] = $rem_id['uid'];
                        $rem_resource_data['permission_level'] = $rem_id['permission_level'];
                    }
                    #echo '<pre>';print_r($rem_resource_data);exit;
                    #concatenate them in the results; THIS SHOWS ONLY REMOTE RESOURCES THAT ARE AVAILABLE AT THE MOMENT!
                    if (is_array($s3ql['where'])) {
                        foreach ($s3ql['where'] as $query_field => $query_value) {
                            if ($query_value != $rem_resource_data[$query_field]) {
                                if (!in_array($query_field, $GLOBALS['COREids'])) {
                                    $rem_resource_data = array();
                                }
                            }
                        }
                    }
                    if (is_array($data) && is_array($rem_resource_data)) {
                        array_push($data, $rem_resource_data);
                    } elseif (is_array($rem_resource_data) && !empty($rem_resource_data)) {
                        $data[] = $rem_resource_data;
                    }
                }
                if ($timer) {
                    $timer->setMarker('Remote data retrieved');
                }
            }
        }
        if (is_array($data)) {
            $data = array_filter($data);
        }
        #now we're ready to display the data
        $pack = compact('data', 'whereScore', 'WhereInfo', 'fromScore', 's3ql', 'key', 'target', 'db', 'user_id', 'cols', 'returnFields', 's3ql_out', 'target', 'uidQuery', 'timer', 'shared_with_query', 'all_data', 'letter', 'model');
        if (!ereg('keys|accesslog|rulelog|statementlog|permission', $s3ql['from'])) {
            $data = includeAllData($pack);
        }
    }
    ##if complete was requested, let's retrieve every link and distribute accordingly rather that querying by uid, would would take much longer
    if ($complete) {
        $alluid = array();
        foreach ($data as $kuid => $data_info) {
            array_push($alluid, $letter . $data_info[$GLOBALS['s3ids'][$element]]);
        }
        include_once S3DB_SERVER_ROOT . '/s3dbcore/dictionary.php';
        $s3qlL = compact('user_id', 'db');
        $s3qlL['from'] = 'links';
        $formatL = 'array';
        $links = query_user_dictionaries($s3qlL, $db, $user_id, $formatL);
        if (is_array($links) && !empty($links)) {
            foreach ($links as $moreData) {
                if ($moreData['uid'] != '') {
                    $foundIt = array_search($moreData['uid'], $alluid);
                    if ($foundIt) {
                        $data[$foundIt]['links'][$moreData['relation']] = $moreData['value'];
                    }
                    #$data[$moreData['uid']]['links'][$moreData['relation']]=$moreData['value'];
                }
            }
        }
        if ($timer) {
            $timer->setMarker('Dictionary data included!');
        }
    }
    if (is_array($data) && !empty($data)) {
        $data = array_combine(range(0, count($data) - 1), $data);
        return $data;
    } else {
        #$emptycols = array(array_combine($cols, array_fill(1,count($cols), '')));
        #echo '<pre>';print_r($emptycols);exit;
        return array();
        #return formatReturn($GLOBALS['error_codes']['no_results'], 'Your query returned no results', $format,'');
    }
}
Exemplo n.º 13
0
   /**
    * Generate the widget and return it as string
    * @return string
    */
   public function generate()
   {
       $arrButtons = array('copy', 'up', 'down', 'delete');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
           $this->import('Database');
           switch ($this->Input->get($strCommand)) {
               case 'copy':
                   array_insert($this->varValue, $this->Input->get('cid'), array($this->varValue[$this->Input->get('cid')]));
                   break;
               case 'up':
                   $this->varValue = array_move_up($this->varValue, $this->Input->get('cid'));
                   break;
               case 'down':
                   $this->varValue = array_move_down($this->varValue, $this->Input->get('cid'));
                   break;
               case 'delete':
                   $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                   break;
           }
           $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
           $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
       }
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || !$this->varValue[0]) {
           $this->varValue = array(array(''));
       }
       // Begin table
       $return .= '<table class="tl_optionwizard" id="ctrl_' . $this->strId . '">
 <thead>
   <tr>
     <th>' . $GLOBALS['TL_LANG']['MSC']['ow_key'] . '</th>
     <th>' . $GLOBALS['TL_LANG']['MSC']['ow_value'] . '</th>
     <th>&nbsp;</th>
   </tr>
 </thead>
 <tbody>';
       $tabindex = 0;
       // Add fields
       for ($i = 0; $i < count($this->varValue); $i++) {
           $return .= '
   <tr>
     <td><input type="text" name="' . $this->strId . '[' . $i . '][key]" id="' . $this->strId . '_key_' . $i . '" class="tl_text_2" tabindex="' . ++$tabindex . '" value="' . specialchars($this->varValue[$i]['key']) . '"></td>
     <td><input type="text" name="' . $this->strId . '[' . $i . '][value]" id="' . $this->strId . '_value_' . $i . '" class="tl_text_2" tabindex="' . ++$tabindex . '" value="' . specialchars($this->varValue[$i]['value']) . '"></td>';
           // Add row buttons
           $return .= '
     <td style="white-space:nowrap; padding-left:3px;">';
           foreach ($arrButtons as $button) {
               $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['ow_' . $button]) . '" onclick="Backend.keyValueWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG']['MSC']['ow_' . $button]) . '</a> ';
           }
           $return .= '</td>
   </tr>';
       }
       return $return . '
 </tbody>
 </table>';
   }
Exemplo n.º 14
0
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $arrColButtons = array('ccopy', 'cmovel', 'cmover', 'cdelete');
       $arrRowButtons = array('rcopy', 'rdrag', 'rup', 'rdown', 'rdelete');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) {
           $this->import('Database');
           switch (\Input::get($strCommand)) {
               case 'ccopy':
                   for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
                       $this->varValue[$i] = array_duplicate($this->varValue[$i], \Input::get('cid'));
                   }
                   break;
               case 'cmovel':
                   for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
                       $this->varValue[$i] = array_move_up($this->varValue[$i], \Input::get('cid'));
                   }
                   break;
               case 'cmover':
                   for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
                       $this->varValue[$i] = array_move_down($this->varValue[$i], \Input::get('cid'));
                   }
                   break;
               case 'cdelete':
                   for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
                       $this->varValue[$i] = array_delete($this->varValue[$i], \Input::get('cid'));
                   }
                   break;
               case 'rcopy':
                   $this->varValue = array_duplicate($this->varValue, \Input::get('cid'));
                   break;
               case 'rup':
                   $this->varValue = array_move_up($this->varValue, \Input::get('cid'));
                   break;
               case 'rdown':
                   $this->varValue = array_move_down($this->varValue, \Input::get('cid'));
                   break;
               case 'rdelete':
                   $this->varValue = array_delete($this->varValue, \Input::get('cid'));
                   break;
           }
           $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
           $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request'))));
       }
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || empty($this->varValue)) {
           $this->varValue = array(array(''));
       }
       // Initialize the tab index
       if (!\Cache::has('tabindex')) {
           \Cache::set('tabindex', 1);
       }
       $tabindex = \Cache::get('tabindex');
       // Begin the table
       $return = '<div id="tl_tablewizard">
 <table id="ctrl_' . $this->strId . '" class="tl_tablewizard">
 <thead>
   <tr>';
       // Add column buttons
       for ($i = 0, $c = count($this->varValue[0]); $i < $c; $i++) {
           $return .= '
     <td style="text-align:center; white-space:nowrap">';
           // Add column buttons
           foreach ($arrColButtons as $button) {
               $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['tw_' . $button]) . '" onclick="Backend.tableWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml(substr($button, 1) . '.gif', $GLOBALS['TL_LANG']['MSC']['tw_' . $button], 'class="tl_tablewizard_img"') . '</a> ';
           }
           $return .= '</td>';
       }
       $return .= '
     <td></td>
   </tr>
 </thead>
 <tbody class="sortable" data-tabindex="' . $tabindex . '">';
       // Add rows
       for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
           $return .= '
   <tr>';
           // Add cells
           for ($j = 0, $d = count($this->varValue[$i]); $j < $d; $j++) {
               $return .= '
     <td class="tcontainer"><textarea name="' . $this->strId . '[' . $i . '][' . $j . ']" class="tl_textarea noresize" tabindex="' . $tabindex++ . '" rows="' . $this->intRows . '" cols="' . $this->intCols . '"' . $this->getAttributes() . '>' . specialchars($this->varValue[$i][$j]) . '</textarea></td>';
           }
           $return .= '
     <td style="white-space:nowrap">';
           // Add row buttons
           foreach ($arrRowButtons as $button) {
               $class = $button == 'rup' || $button == 'rdown' ? ' class="button-move"' : '';
               if ($button == 'rdrag') {
                   $return .= \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"');
               } else {
                   $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG']['MSC']['tw_' . $button]) . '" onclick="Backend.tableWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml(substr($button, 1) . '.gif', $GLOBALS['TL_LANG']['MSC']['tw_' . $button], 'class="tl_tablewizard_img"') . '</a> ';
               }
           }
           $return .= '</td>
   </tr>';
       }
       // Store the tab index
       \Cache::set('tabindex', $tabindex);
       $return .= '
 </tbody>
 </table>
 </div>
 <script>Backend.tableWizardResize()</script>';
       return $return;
   }
Exemplo n.º 15
0
 public static function fix()
 {
     $widgets = twidgets::i();
     foreach ($widgets->classes as $classname => &$items) {
         foreach ($items as $i => $item) {
             if (!isset($widgets->items[$item['id']])) {
                 unset($items[$i]);
             }
         }
     }
     $views = tviews::i();
     foreach ($views->items as &$viewitem) {
         if ($viewitem['id'] != 1 && !$viewitem['customsidebar']) {
             continue;
         }
         unset($sidebar);
         foreach ($viewitem['sidebars'] as &$sidebar) {
             for ($i = count($sidebar) - 1; $i >= 0; $i--) {
                 //echo $sidebar[$i]['id'], '<br>';
                 if (!isset($widgets->items[$sidebar[$i]['id']])) {
                     array_delete($sidebar, $i);
                 }
             }
         }
     }
     $views->save();
 }
Exemplo n.º 16
0
 if (get_var('group_disable_sending_private') == 1) {
     if (!in_array($group_id, $group_disable_sending_private_ex)) {
         $group_disable_sending_private_ex[] = $group_id;
     }
 } else {
     if (in_array($group_id, $group_disable_sending_private_ex)) {
         $group_disable_sending_private_ex = array_delete($group_disable_sending_private_ex, $group_id);
     }
 }
 if (get_var('group_disable_sending_rooms') == 1) {
     if (!in_array($group_id, $group_disable_sending_rooms_ex)) {
         $group_disable_sending_rooms_ex[] = $group_id;
     }
 } else {
     if (in_array($group_id, $group_disable_sending_rooms_ex)) {
         $group_disable_sending_rooms_ex = array_delete($group_disable_sending_rooms_ex, $group_id);
     }
 }
 $group_disable_arrowchat_new = ltrim(implode(",", $group_disable_arrowchat_ex), ',');
 $group_disable_video_new = ltrim(implode(",", $group_disable_video_ex), ',');
 $group_disable_apps_new = ltrim(implode(",", $group_disable_apps_ex), ',');
 $group_disable_rooms_new = ltrim(implode(",", $group_disable_rooms_ex), ',');
 $group_disable_uploads_new = ltrim(implode(",", $group_disable_uploads_ex), ',');
 $group_disable_sending_private_new = ltrim(implode(",", $group_disable_sending_private_ex), ',');
 $group_disable_sending_rooms_new = ltrim(implode(",", $group_disable_sending_rooms_ex), ',');
 $result = $db->execute("\n\t\t\tUPDATE arrowchat_config \n\t\t\tSET config_value = CASE \n\t\t\t\tWHEN config_name = 'group_disable_arrowchat' THEN '" . $db->escape_string($group_disable_arrowchat_new) . "'\n\t\t\t\tWHEN config_name = 'group_disable_video' THEN '" . $db->escape_string($group_disable_video_new) . "'\n\t\t\t\tWHEN config_name = 'group_disable_apps' THEN '" . $db->escape_string($group_disable_apps_new) . "'\n\t\t\t\tWHEN config_name = 'group_disable_rooms' THEN '" . $db->escape_string($group_disable_rooms_new) . "'\n\t\t\t\tWHEN config_name = 'group_disable_uploads' THEN '" . $db->escape_string($group_disable_uploads_new) . "'\n\t\t\t\tWHEN config_name = 'group_disable_sending_private' THEN '" . $db->escape_string($group_disable_sending_private_new) . "'\n\t\t\t\tWHEN config_name = 'group_disable_sending_rooms' THEN '" . $db->escape_string($group_disable_sending_rooms_new) . "'\n\t\t\tEND WHERE config_name IN ('group_disable_arrowchat', 'group_disable_video', 'group_disable_apps', 'group_disable_rooms', 'group_disable_uploads', 'group_disable_sending_private', 'group_disable_sending_rooms')\n\t\t");
 if ($result) {
     $group_disable_arrowchat = $group_disable_arrowchat_new;
     $group_disable_video = $group_disable_video_new;
     $group_disable_apps = $group_disable_apps_new;
     $group_disable_rooms = $group_disable_rooms_new;
Exemplo n.º 17
0
    /**
     * Generate the widget and return it as string
     * @return string
     */
    public function generate()
    {
        // load the callback data if there's any (do not do this in __set() already because then we don't have access to currentRecord)
        if (is_array($this->arrCallback)) {
            $this->import($this->arrCallback[0]);
            $this->columnFields = $this->{$this->arrCallback[0]}->{$this->arrCallback[1]}($this);
        }
        $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/multicolumnwizard/html/js/multicolumnwizard_' . strtolower(TL_MODE) . '.js';
        $GLOBALS['TL_CSS'][] = 'system/modules/multicolumnwizard/html/css/multicolumnwizard.css';
        $this->strCommand = 'cmd_' . $this->strField;
        // Change the order
        if ($this->Input->get($this->strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
            switch ($this->Input->get($this->strCommand)) {
                case 'copy':
                    $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid'));
                    break;
                case 'up':
                    $this->varValue = array_move_up($this->varValue, $this->Input->get('cid'));
                    break;
                case 'down':
                    $this->varValue = array_move_down($this->varValue, $this->Input->get('cid'));
                    break;
                case 'delete':
                    $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                    break;
            }
            if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'File') {
                $this->Config->update(sprintf("\$GLOBALS['TL_CONFIG']['%s']", $this->strField), serialize($this->varValue));
            } else {
                if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'])) {
                    $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'];
                    require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer);
                    $dc = new $dataContainer($this->strTable);
                    $dc->field = $objWidget->id;
                    $dc->inputName = $objWidget->id;
                    foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'] as $callback) {
                        $this->import($callback[0]);
                        $this->{$callback}[0]->{$callback}[1](serialize($this->varValue), $dc);
                    }
                } else {
                    $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
                }
            }
            // Reload the page
            $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
        }
        $arrUnique = array();
        $arrDatepicker = array();
        $arrHeaderItems = array();
        foreach ($this->columnFields as $strKey => $arrField) {
            // Store unique fields
            if ($arrField['eval']['unique']) {
                $arrUnique[] = $strKey;
            }
            // Store date picker fields
            if ($arrField['eval']['datepicker']) {
                $arrDatepicker[] = $strKey;
            }
            if ($arrField['inputType'] == 'hidden') {
                continue;
            }
        }
        $intNumberOfRows = max(count($this->varValue), 1);
        // always show the minimum number of rows if set
        if ($this->minCount && $intNumberOfRows < $this->minCount) {
            $intNumberOfRows = $this->minCount;
        }
        $arrItems = array();
        // Add input fields
        for ($i = 0; $i < $intNumberOfRows; $i++) {
            $this->activeRow = $i;
            $strHidden = '';
            // Walk every column
            foreach ($this->columnFields as $strKey => $arrField) {
                $strWidget = '';
                // load row specific data (useful for example for default values in different rows)
                if (isset($this->arrRowSpecificData[$i][$strKey])) {
                    $arrField = array_merge($arrField, $this->arrRowSpecificData[$i][$strKey]);
                }
                $objWidget = $this->initializeWidget($arrField, $i, $strKey, $this->varValue[$i][$strKey]);
                // load errors if there are any
                if (!empty($this->arrWidgetErrors[$strKey][$i])) {
                    foreach ($this->arrWidgetErrors[$strKey][$i] as $strErrorMsg) {
                        $objWidget->addError($strErrorMsg);
                    }
                }
                if ($objWidget === null) {
                    continue;
                } elseif (is_string($objWidget)) {
                    $strWidget = $objWidget;
                } elseif ($arrField['inputType'] == 'hidden') {
                    $strHidden .= $objWidget->generate();
                    continue;
                } else {
                    $datepicker = '';
                    // Datepicker
                    if ($arrField['eval']['datepicker']) {
                        $rgxp = $arrField['eval']['rgxp'];
                        $format = $GLOBALS['TL_CONFIG'][$rgxp . 'Format'];
                        switch ($rgxp) {
                            case 'datim':
                                $time = ",\n      timePicker:true";
                                break;
                            case 'time':
                                $time = ",\n      timePickerOnly:true";
                                break;
                            default:
                                $time = '';
                                break;
                        }
                        $datepicker = ' <img src="plugins/datepicker/icon.gif" width="20" height="20" alt="" id="toggle_' . $objWidget->id . '" style="vertical-align:-6px;">
                          <script>

                          window.datepicker_' . $this->strName . '_' . $strKey . ' = new DatePicker(\'#ctrl_' . $objWidget->id . '\', {
                          allowEmpty:true,
                          toggleElements:\'#toggle_' . $objWidget->id . '\',
                          pickerClass:\'datepicker_dashboard\',
                          format:\'' . $format . '\',
                          inputOutputFormat:\'' . $format . '\',
                          positionOffset:{x:130,y:-185}' . $time . ',
                          startDay:' . $GLOBALS['TL_LANG']['MSC']['weekOffset'] . ',
                          days:[\'' . implode("','", $GLOBALS['TL_LANG']['DAYS']) . '\'],
                          dayShort:' . $GLOBALS['TL_LANG']['MSC']['dayShortLength'] . ',
                          months:[\'' . implode("','", $GLOBALS['TL_LANG']['MONTHS']) . '\'],
                          monthShort:' . $GLOBALS['TL_LANG']['MSC']['monthShortLength'] . '
                          });

                          </script>';
                        $datepicker = $this->getMcWDatePickerString($objWidget->id, $strKey, $rgxp);
                        /* $datepicker = '<script>
                           window.addEvent(\'domready\', function() {
                           ' . sprintf($this->getDatePickerString(), 'ctrl_' . $objWidget->strId) . '
                           });
                           </script>'; */
                    }
                    // Add custom wizard
                    if (is_array($arrField['wizard'])) {
                        $wizard = '';
                        $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'];
                        require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer);
                        $dc = new $dataContainer($this->strTable);
                        $dc->field = $objWidget->id;
                        $dc->inputName = $objWidget->id;
                        foreach ($arrField['wizard'] as $callback) {
                            $this->import($callback[0]);
                            $wizard .= $this->{$callback}[0]->{$callback}[1]($dc, $objWidget);
                        }
                        $objWidget->wizard = $wizard;
                    }
                    $strWidget = $objWidget->parse() . $datepicker;
                }
                // Build array of items
                if ($arrField['eval']['columnPos'] != '') {
                    $arrItems[$i][$objWidget->columnPos]['entry'] .= $strWidget;
                    $arrItems[$i][$objWidget->columnPos]['valign'] = $arrField['eval']['valign'];
                    $arrItems[$i][$objWidget->columnPos]['tl_class'] = $arrField['eval']['tl_class'];
                } else {
                    $arrItems[$i][$strKey] = array('entry' => $strWidget, 'valign' => $arrField['eval']['valign'], 'tl_class' => $arrField['eval']['tl_class']);
                }
            }
        }
        return $this->blnTableless ? $this->generateDiv($arrUnique, $arrDatepicker, $strHidden, $arrItems) : $this->generateTable($arrUnique, $arrDatepicker, $strHidden, $arrItems);
    }
Exemplo n.º 18
0
function apiQuery($s3ql, $user_proj = false)
{
    extract($s3ql);
    #if it does not exist, create it and save it in config.inc.php;
    if (!$user_proj) {
        $user_proj = create_authentication_proj($s3ql['db'], $s3ql['user_id']);
    }
    if (!$user_proj) {
        $msg = "A project to manage users has not been created. This project can only be created by the generic Admin users. Please add your Admin key to apilogin.php to create it automatically.";
        return array(false, formatReturn('5', $msg, $format, ''));
        exit;
    }
    if ($s3ql['insert'] != '') {
        $target = $s3ql['insert'];
        $action = 'insert';
    }
    if ($s3ql['update'] != '') {
        $target = $s3ql['update'];
        $action = 'update';
    }
    if ($s3ql['delete'] != '') {
        $target = $s3ql['delete'];
        $action = 'delete';
    }
    if ($s3ql['from'] != '') {
        $target = $s3ql['from'];
        $action = 'select';
    }
    if ($target == 'authorities') {
        $target = 'authority';
    }
    if ($action == 'insert') {
        switch ($target) {
            case 'authentication':
                #does the user_id specified exist?
                #authentication_id is to always be built from what is provided
                $user2add = ereg_replace('^U', '', $s3ql['where']['user_id']);
                #validate the authentication inputs
                if ($s3ql['where']['authentication_id'] == '') {
                    if (!$s3ql['where']['authority'] || !$s3ql['where']['username']) {
                        $msg = formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide all the necessary fields. These include either &lt;authentication_id&gt; or &lt;protocol&gt, &lt;authority&gt and &lt;username&gt', $_REQUEST['format'], '');
                        return array(false, $msg);
                        exit;
                    } else {
                        $prot = $s3ql['where']['protocol'];
                        $auth = $s3ql['where']['authority'];
                        $email = $s3ql['where']['username'];
                        $s3ql['where']['authentication_id'] = ($prot != 'http' ? $prot . ':' : '') . $auth . ':' . $email;
                        $s3ql['where'] = array_delete($s3ql['where'], array('protocol', 'authority', 'username'));
                    }
                }
                if ($s3ql['where']['user_id'] == '') {
                    $s3ql['where']['user_id'] = $user_id;
                    $user2add = $user_id;
                    #$msg= (formatReturn($GLOBALS['error_codes']['something_missing'],'Please provide the user_id whose authentication you wish to add.', $format,''));
                    #return (array(false, $msg));
                    #exit;
                }
                #this function will actually validate the authentication feasibility
                list($valid, $msg) = validate_authentication($s3ql, $user_id, $db);
                if ($valid) {
                    #does the user_id have an item assigned to him already?
                    while (!$user_proj['users']['items'][$user2add]['item_id'] && $try < 5) {
                        $user_proj = insert_authentication_tuple(array('user_proj' => $user_proj, 'user_id' => '1', 'db' => $db, 's3ql' => $s3ql));
                        #$user_proj = insert_authentication_tuple(compact('user_proj', 'user_id','db','s3ql'));
                        $try++;
                    }
                    if ($user_proj['users']['items'][$user2add]['item_id'] == '') {
                        $msg = formatReturn($GLOBALS['error_codes']['something_missing'], "Could not create an item for this user.", $format, '');
                        return array(false, $msg);
                        exit;
                    }
                    #now let's create an statement for this authentication. Since these can be many, we run the query either way and let s3ql tell us whether this already exists
                    if (!is_array($user_proj[$user2add]['R' . $user_proj['email']['rule_id']])) {
                        $user_proj[$user2add]['R' . $user_proj['email']['rule_id']] = array();
                    }
                    $s3ql_new = compact('user_id', 'db');
                    $s3ql_new['insert'] = 'statement';
                    $s3ql_new['where']['rule_id'] = $user_proj['email']['rule_id'];
                    $s3ql_new['where']['item_id'] = $user_proj['users']['items'][$user2add]['item_id'];
                    $s3ql_new['where']['value'] = $s3ql['where']['authentication_id'];
                    $s3ql_new['format'] = 'php';
                    $done = S3QLaction($s3ql_new);
                    $msg = unserialize($done);
                    $msg = $msg[0];
                    if ($msg['statement_id']) {
                        array_push($user_proj[$user2add]['R' . $user_proj['email']['rule_id']], $s3ql['where']['authentication_id']);
                        file_put_contents($GLOBALS['uploads'] . '/userManage.s3db', serialize($user_proj));
                        $msg1 = formatReturn($GLOBALS['error_codes']['success'], "Authentication inserted", $format, array('authentication_id' => $s3ql['where']['authentication_id']));
                        return array(false, $msg1);
                        exit;
                    } elseif ($msg['error_code'] == '4') {
                        $msg1 = formatReturn('4', 'The provided authentication already exists for this user.', $format, '');
                        return array(false, $msg1);
                        exit;
                    } elseif ($msg['error_code'] == '11') {
                        $msg1 = formatReturn('7', 'Invalid authentication format. ' . $msg['message'], $format, '');
                        return array(false, $msg1);
                        exit;
                    } elseif ($msg['error_code'] == '4') {
                        $msg1 = formatReturn($msg['error_code'], "Authentication already exists.", $format, '');
                        return array(false, $msg1);
                        exit;
                    } else {
                        $msg1 = formatReturn($msg['error_code'], $msg['message'], $format, '');
                        return array(false, $msg1);
                        exit;
                    }
                } else {
                    return array(false, $msg);
                }
                break;
            default:
        }
        //if($q_syntax['where']['authority_id']=='')
        #return ($user_proj);
        return true;
    } elseif ($action == 'select') {
        #if authentication is being asked for
        switch ($target) {
            case 'authentication':
                ##if user id is not indicated in the query, use self. S3DB will take care of permisison management
                if ($s3ql['where']['user_id'] != '') {
                    $user2find = ereg_replace('^U', '', $s3ql['where']['user_id']);
                    if (!$user_proj[$user2find]['I']) {
                        $s3ql_new = compact('user_id', 'db');
                        $s3ql_new['from'] = 'statement';
                        $s3ql_new['where']['rule_id'] = $user_proj['user_id']['rule_id'];
                        $s3ql_new['where']['value'] = $user2find;
                        $done = S3QLaction($s3ql_new);
                        if (is_array($done)) {
                            $user_proj[$user2find]['I'] = $done[0]['item_id'];
                            $user_proj[$user2find]['R' . $user_proj['user_id']['rule_id']] = $done[0]['statement_id'];
                        }
                    }
                    if ($user_proj[$user2find]['I'] != '') {
                        $s3ql_new = compact('user_id', 'db');
                        $s3ql_new['from'] = 'statements';
                        $s3ql_new['where']['item_id'] = $user_proj[$user2find]['I'];
                        $s3ql_new['where']['rule_id'] = $user_proj['email']['rule_id'];
                        $user_authentications[$user2find] = S3QLaction($s3ql_new);
                    } else {
                        $data = array();
                    }
                } else {
                    $s3ql_new = compact('user_id', 'db');
                    $s3ql_new['from'] = 'statements';
                    $s3ql_new['where']['rule_id'] = $user_proj['user_id']['rule_id'];
                    $users = S3QLaction($s3ql_new);
                    foreach ($users as $user_info) {
                        $s3ql_new = compact('user_id', 'db');
                        $s3ql_new['from'] = 'statements';
                        $s3ql_new['where']['item_id'] = $user_info['item_id'];
                        $s3ql_new['where']['rule_id'] = $user_proj['email']['rule_id'];
                        $tmp = S3QLaction($s3ql_new);
                        $user_authentications[$user_info['value']] = $tmp;
                    }
                }
                #to display data, choose the headers
                $headers = array('user_id', 'authentication_id', 'created_on');
                if (is_array($user_authentications)) {
                    foreach ($user_authentications as $user4auth => $auths) {
                        if (!empty($auths)) {
                            foreach ($auths as $auth_info) {
                                $data[] = array('user_id' => $user4auth, 'authentication_id' => $auth_info['value'], 'created_on' => $auth_info['created_on']);
                            }
                        }
                    }
                    return array(true, $data, $headers);
                } else {
                    $msg = formatReturn($GLOBALS['error_codes']['something_missing'], "No authentications were found matching your search criteria!", $_REQUEST['format'], '');
                    return array(false, $msg);
                }
                break;
            case 'authority':
                #what is the collection_id of the collection that holds autohorittier
                $s3qlnew = compact('user_id', 'db');
                $s3qlnew['from'] = 'items';
                $s3qlnew['where']['collection_id'] = $user_proj['authorities']['collection_id'];
                #ups, just noticed i called it authorities; hehe, i'll leave it :-)
                $authorities = S3QLaction($s3qlnew);
                if (is_array($authorities) && !empty($authorities)) {
                    foreach ($authorities as $tmp) {
                        $authority_data[$tmp['item_id']] = array();
                    }
                }
                if (is_array($authorities) && !empty($authorities)) {
                    #now find, for item, for each rule of authorities, the values
                    $headers2show[] = 'item_id';
                    foreach ($user_proj['authorities']['rules'] as $auth_attr) {
                        $s3qlnew = compact('user_id', 'db');
                        $s3qlnew['from'] = 'statements';
                        $s3qlnew['where']['rule_id'] = $auth_attr;
                        $data_values = S3QLaction($s3qlnew);
                        #now reorganize them according to item_id
                        if (is_array($data_values) && !empty($data_values)) {
                            foreach ($data_values as $stat) {
                                #we expect 1 value per rule per item, but in case there is more, this is the right time to do it :-)
                                if (is_array($authority_data[$stat['item_id']])) {
                                    if (!is_array($authority_data[$stat['item_id']][$auth_attr])) {
                                        $authority_data[$stat['item_id']][$auth_attr] = array();
                                    }
                                    array_push($authority_data[$stat['item_id']][$auth_attr], $stat);
                                }
                                #now stored header data
                                if (!in_array($stat['object'], $headers2show)) {
                                    $headers2show[$stat['rule_id']] = $stat['object'];
                                }
                            }
                        }
                    }
                    $ItemLine = array();
                    foreach ($authority_data as $item_id => $rule_values) {
                        $extraItemLine = 0;
                        $thisItemLine = array();
                        $thisItemLine['item_id'] = $item_id;
                        #foreach ($rule_values as $rule_id=>$rule_value_stats) {
                        foreach ($headers2show as $rule_id => $headerName) {
                            $rule_value_stats = array();
                            if ($headerName != 'item_id') {
                                if ($rule_values[$rule_id] != '') {
                                    $rule_value_stats = $rule_values[$rule_id];
                                }
                                #every item will have a line. Except if the item has more than  1 statement per headers, in which case it will have as many as the number of stats
                                if (count($rule_value_stats) > $extraItemLine) {
                                    $extraItemLine = count($rule_value_stats);
                                }
                                if ($extraItemLine <= 1) {
                                    $thisItemLine[$headers2show[$rule_id]] = $rule_value_stats[0]['value'];
                                } else {
                                    #echo '<pre>';print_r($rule_value_stats);
                                    #
                                }
                                #$item_data_line[] =
                                #array('item_id'=>$item_id,
                                #	  $headers2show
                            }
                        }
                        array_push($ItemLine, $thisItemLine);
                    }
                    $data = $ItemLine;
                    #save it
                    $user_proj['authorities']['local_data'] = $data;
                    file_put_contents($GLOBALS['uploads'] . 'user_proj', serialize($user_proj));
                    #now it's time to trim the data according to user requests
                    #now discover which authority is being requested
                    $newData = array();
                    foreach ($data as $tuple) {
                        if ($s3ql['where'] != '') {
                            #match the where array keys with the data array keys
                            $query = array_intersect(array_keys($s3ql['where']), array_keys($tuple));
                            foreach ($query as $query_attr) {
                                #does it have regular expressions?
                                $qval = '';
                                ereg('(\\~|\\!|\\i )(.*)', $s3ql['where'][$query_attr], $qval);
                                if (!$qval) {
                                    #if no reg exp are specified, do a precise match
                                    if ($s3ql['where'][$query_attr] != $tuple[$query_attr]) {
                                        $tuple = array();
                                    }
                                } elseif ($qval[1] == '~') {
                                    if (!ereg($qval[2], $tuple[$query_attr])) {
                                        $tuple = array();
                                    }
                                } elseif ($qval[1] == 'i ') {
                                    if (!eregi($qval[2], $tuple[$query_attr])) {
                                        $tuple = array();
                                    }
                                } elseif ($qval[1] == '!') {
                                    #when what is asked for is different, clear if the are equal
                                    if ($qval[2] == $tuple[$query_attr]) {
                                        $tuple = array();
                                    }
                                }
                            }
                        }
                        $newData[] = $tuple;
                        #if(eregi('^'.$projAuthority['DisplayLabel'].'$',$authority)){
                        #	$reqAuth = $projAuthority;
                        #
                        #}
                    }
                    $data = array_values(array_filter($newData));
                    #save it
                    $user_proj['authoritities']['local_data'] = $data;
                    file_put_contents($GLOBALS['uploads'] . 'user_proj', serialize($user_proj));
                    $headers = array_values($headers2show);
                    #return (array(true, $data,$headers));
                    #exit;
                }
                #now for each of the items, find the statements associated and create the corresponding array
                break;
            case 'protocol':
                $s3qlnew = compact('user_id', 'db');
                $s3qlnew['from'] = 'items';
                $s3qlnew['where']['collection_id'] = $user_proj['protocols']['collection_id'];
                $done = S3QLaction($s3qlnew);
                $headers = array('item_id', 'label', 'created_on');
                if (is_array($done)) {
                    foreach ($done as $protocol) {
                        $data[] = array('item_id' => $protocol['item_id'], 'label' => $protocol['notes'], 'created_on' => $protocol['created_on']);
                    }
                    #return (array(true,$data,$headers));
                }
                break;
            default:
                echo "Funcionality not developed yet.";
                exit;
        }
        #now it's time to trim the data according to user requests
        #now discover which authority is being requested
        $newData = array();
        foreach ($data as $tuple) {
            if ($s3ql['where'] != '') {
                #match the where array keys with the data array keys
                $query = array_intersect(array_keys($s3ql['where']), array_keys($tuple));
                foreach ($query as $query_attr) {
                    #does it have regular expressions?
                    $qval = '';
                    ereg('(\\~|\\!|\\i )(.*)', $s3ql['where'][$query_attr], $qval);
                    if (!$qval) {
                        #if no reg exp are specified, do a precise match
                        if ($s3ql['where'][$query_attr] != $tuple[$query_attr]) {
                            $tuple = array();
                        }
                    } elseif ($qval[1] == '~') {
                        if (!ereg($qval[2], $tuple[$query_attr])) {
                            $tuple = array();
                        }
                    } elseif ($qval[1] == 'i ') {
                        if (!eregi($qval[2], $tuple[$query_attr])) {
                            $tuple = array();
                        }
                    } elseif ($qval[1] == '!') {
                        #when what is asked for is different, clear if the are equal
                        if ($qval[2] == $tuple[$query_attr]) {
                            $tuple = array();
                        }
                    }
                }
            }
            $newData[] = $tuple;
        }
        $data = array_values(array_filter($newData));
        if (is_array($data)) {
            return array(true, $data, $headers);
        }
    } elseif ($action == 'delete' || $action == 'update') {
        #only authentication_id is accepted as a parameter for deletion.
        if ($target == 'authentication') {
            if ($s3ql['where']['authentication_id'] == '') {
                $msg = formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide the value for &lt;authentication_id&gt; to be updated/deleted', $_REQUEST['format'], '');
                return array(false, $msg);
                exit;
            } elseif ($action == 'update' && $s3ql['set']['authentication_id'] == '') {
                $msg = formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide the authentication_id to replace.', $_REQUEST['format'], '');
                return array(false, $msg);
                exit;
            } else {
                #delete an authentication will delete a statement. Which statement_id are we looking for?
                $s3ql_new = compact('user_id', 'db');
                $s3ql_new['from'] = 'statements';
                $s3ql_new['where']['rule_id'] = $user_proj['email']['rule_id'];
                $s3ql_new['where']['value'] = $s3ql['where']['authentication_id'];
                $done = S3QLaction($s3ql_new);
                if (!$done[0]['statement_id']) {
                    $msg = formatReturn($GLOBALS['error_codes']['something_missing'], 'Authentication ' . $s3ql['where']['authentication_id'] . ' was not found or user does not have permission to delete.', $_REQUEST['format'], '');
                    return array(false, $msg);
                    exit;
                } else {
                    #we will let s3db permission manageent take care of permission to delete
                    $s3ql_new = compact('user_id', 'db');
                    $s3ql_new[$action] = 'statement';
                    $s3ql_new['where']['statement_id'] = $done[0]['statement_id'];
                    if ($action == 'update') {
                        $s3ql_new['set']['value'] = $s3ql['set']['authentication_id'];
                    }
                    $done = S3QLaction($s3ql_new);
                    if ($done['error_code'] == '0') {
                        return array(true, $done);
                    } else {
                        return array(false, $done);
                    }
                }
            }
        }
    }
}
Exemplo n.º 19
0
 public function deletehtml($filename)
 {
     if (!($filename = $this->normfilename($filename))) {
         return false;
     }
     if (false === ($i = array_search($filename, $this->html))) {
         return false;
     }
     array_delete($this->html, $i);
     $this->save();
 }
Exemplo n.º 20
0
 /**
  * Generate the widget and return it as string
  * @return string
  */
 public function generate()
 {
     if (is_array($GLOBALS['TL_JAVASCRIPT'])) {
         array_insert($GLOBALS['TL_JAVASCRIPT'], 1, 'system/modules/MultiTextWizard/html/js/multitext.js');
     } else {
         $GLOBALS['TL_JAVASCRIPT'] = array('system/modules/MultiTextWizard/html/js/multitext.js');
     }
     $arrButtons = array('rnew', 'rcopy', 'rup', 'rdown', 'rdelete');
     $strCommand = 'cmd_' . $this->strField;
     $emptyarray = array();
     for ($i = 0; $i < count($this->arrColumns); $i++) {
         array_push($emptyarray, '');
     }
     // Change the order
     if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
         $this->import('Database');
         switch ($this->Input->get($strCommand)) {
             case 'rnew':
                 array_insert($this->varValue, $this->Input->get('cid') + 1, array($emptyarray));
                 break;
             case 'rcopy':
                 $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid'));
                 break;
             case 'rup':
                 $this->varValue = array_move_up($this->varValue, $this->Input->get('cid'));
                 break;
             case 'rdown':
                 $this->varValue = array_move_down($this->varValue, $this->Input->get('cid'));
                 break;
             case 'rdelete':
                 $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                 break;
         }
         $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
         $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
     }
     // Make sure there is at least an empty array
     if (!is_array($this->varValue) || !$this->varValue[0]) {
         $this->varValue = array($emptyarray);
     }
     $objTemplate = new BackendTemplate($this->strMultitextTemplate);
     $objTemplate->strId = $this->strId;
     $objTemplate->attributes = $this->getAttributes();
     $objTemplate->arrColumns = $this->arrColumns;
     $objTemplate->varValue = $this->varValue;
     $objTemplate->arrMultiErrors = $this->arrMultiErrors;
     $buttons = array();
     $hasTitles = array_key_exists('buttonTitles', $this->arrConfiguration) && is_array($this->arrConfiguration['buttonTitles']);
     foreach ($arrButtons as $button) {
         $buttontitle = $hasTitles && array_key_exists($button, $this->arrConfiguration['buttonTitles']) ? $this->arrConfiguration['buttonTitles'][$button] : $GLOBALS['TL_LANG'][$this->strTable][$button][0];
         array_push($buttons, array('href' => $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=%s&amp;id=' . $this->currentRecord), 'title' => specialchars($buttontitle), 'onclick' => 'MultiText.multitextWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;', 'img' => $this->generateImage(substr($button, 1) . '.gif', $GLOBALS['TL_LANG'][$this->strTable][$button][0], 'class="tl_multitextwizard_img"')));
     }
     $objTemplate->arrButtons = $buttons;
     return $objTemplate->parse();
 }
Exemplo n.º 21
0
     $result = mysql_query("UPDATE articles SET rand='' WHERE id='{$Album}'") or die(mysql_error());
     // UPDATE ALL TRANSFERRED ARTICLE INFORMATION \\
     $result = mysql_query("UPDATE transfer SET trash='1' WHERE id='{$TransferId}'") or die(mysql_error());
     $result = mysql_query("UPDATE transfer SET trash='1' WHERE url='{$Article_Url}'") or die(mysql_error());
 } else {
     // UN-LINK OLD TAGS FROM ARTICLE \\
     $UnlinkTag = explode(",", $Tags);
     $query = "SELECT * FROM articles WHERE id='{$Article_Id}'";
     $result = mysql_query($query) or die(mysql_error());
     $row = mysql_fetch_array($result);
     $row = PbUnSerial($row);
     $SRTags = $row["other"]["tags"];
     if ($SRTags == "") {
     } else {
         $SRTags = explode(",", $SRTags);
         $TagRemove = array_delete($UnlinkTag, $SRTags);
         $Count = "0";
         foreach ($TagRemove as $value) {
             $Query = "SELECT * FROM cw_tags WHERE name='{$value}'";
             $Result = mysql_query($Query) or die(mysql_error());
             $Row = mysql_fetch_array($Result);
             $ListTagId = $Row["id"];
             $ListTag = OtarDecrypt($key, $Row[content]);
             $Tag_Key = array_search($Article_Id, $ListTag);
             unset($ListTag[$Tag_Key]);
             $NewTagArray = OtarEncrypt($key, $ListTag);
             $result = mysql_query("UPDATE cw_tags SET content='{$NewTagArray}' WHERE id='{$ListTagId}'") or die(mysql_error());
         }
     }
     // PROCESS GALLERY IMAGE UPLOADS \\
     $Array["galleryupload"]["id"] = $Article_Id;
Exemplo n.º 22
0
   /**
    * Generate the widget and return it as string
    * @return string
    */
   public function generate()
   {
       $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/isotope/html/backend.js';
       if (!is_array($this->varValue)) {
           $this->varValue = array(array('name' => 'gallery'), array('name' => 'thumbnail'), array('name' => 'medium'), array('name' => 'large'));
       }
       $arrButtons = array('copy', 'delete');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
           switch ($this->Input->get($strCommand)) {
               case 'copy':
                   $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid'));
                   break;
               case 'delete':
                   $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                   break;
           }
       }
       // Begin table
       $return .= '<table class="tl_imagewatermarkwizard" id="ctrl_' . $this->strId . '">
 <thead>
   <tr>
     <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwName'] . '</th>
     <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwWidth'] . '</th>
     <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwHeight'] . '</th>
     <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwMode'] . '</th>
     <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwWatermark'] . '</th>
     <th>' . $GLOBALS['TL_LANG'][$this->strTable]['iwPosition'] . '</th>
     <th>&nbsp;</th>
   </tr>
 </thead>
 <tbody>';
       foreach ($this->varValue as $i => $size) {
           $arrModes = array();
           $arrPositions = array();
           foreach ($this->arrOptions as $arrOption) {
               $arrModes[] = sprintf('<option value="%s"%s>%s</option>', specialchars($arrOption['value']), is_array($this->varValue[$i]) && $this->varValue[$i]['mode'] == $arrOption['value'] ? ' selected="selected"' : '', $arrOption['label']);
           }
           foreach (array('tl', 'tc', 'tr', 'bl', 'bc', 'br', 'cc') as $option) {
               $arrPositions[] = sprintf('<option value="%s"%s>%s</option>', specialchars($option), is_array($this->varValue[$i]) && $this->varValue[$i]['position'] == $option ? ' selected="selected"' : '', $GLOBALS['TL_LANG'][$this->strTable][$option]);
           }
           $filepicker = $this->generateImage('pickfile.gif', $GLOBALS['TL_LANG']['MSC']['filepicker'], 'style="vertical-align:top; cursor:pointer;" onclick="Backend.pickFile(this.getPrevious())"');
           $return .= '
   <tr>
     <td><input type="text" name="' . $this->strName . '[' . $i . '][name]" id="' . $this->strId . '_name_' . $i . '" class="tl_text_4" value="' . specialchars($this->varValue[$i]['name']) . '""></td>
     <td><input type="text" name="' . $this->strName . '[' . $i . '][width]" id="' . $this->strId . '_width_' . $i . '" class="tl_text_4" value="' . specialchars($this->varValue[$i]['width']) . '""></td>
     <td><input type="text" name="' . $this->strName . '[' . $i . '][height]" id="' . $this->strId . '_height_' . $i . '" class="tl_text_4" value="' . specialchars($this->varValue[$i]['height']) . '""></td>
     <td><select name="' . $this->strName . '[' . $i . '][mode]" id="' . $this->strId . '_mode_' . $i . '" class="tl_select_interval" onfocus="Backend.getScrollOffset();">' . implode(' ', $arrModes) . '</select></td>
     <td><input type="text" name="' . $this->strName . '[' . $i . '][watermark]" id="' . $this->strId . '_watermark_' . $i . '" class="tl_text_2" value="' . specialchars($this->varValue[$i]['watermark']) . '"">' . $filepicker . '</td>
     <td><select name="' . $this->strName . '[' . $i . '][position]" id="' . $this->strId . '_position_' . $i . '" class="tl_select_unit" onfocus="Backend.getScrollOffset();">' . implode(' ', $arrPositions) . '</select></td>';
           $return .= '
     <td>';
           foreach ($arrButtons as $button) {
               $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button]) . '" onclick="Isotope.imageWatermarkWizard(this, \'' . $button . '\',  \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button], 'class="tl_listwizard_img"') . '</a> ';
           }
           $return .= '</td>
   </tr>';
       }
       return $return . '
 </tbody>
 </table>';
   }
Exemplo n.º 23
0
   /**
    * Generate the widget and return it as string
    * @return string
    */
   public function generate()
   {
       $arrButtons = array('copy', 'drag', 'up', 'down', 'delete');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if (\Input::get($strCommand) && is_numeric(\Input::get('cid')) && \Input::get('id') == $this->currentRecord) {
           $this->import('Database');
           switch (\Input::get($strCommand)) {
               case 'copy':
                   array_insert($this->varValue, \Input::get('cid'), array($this->varValue[\Input::get('cid')]));
                   break;
               case 'up':
                   $this->varValue = array_move_up($this->varValue, \Input::get('cid'));
                   break;
               case 'down':
                   $this->varValue = array_move_down($this->varValue, \Input::get('cid'));
                   break;
               case 'delete':
                   $this->varValue = array_delete($this->varValue, \Input::get('cid'));
                   break;
           }
           $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
           $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', \Environment::get('request'))));
       }
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || !$this->varValue[0]) {
           $this->varValue = array(array(''));
       }
       // Initialize the tab index
       if (!\Cache::has('tabindex')) {
           \Cache::set('tabindex', 1);
       }
       $tabindex = \Cache::get('tabindex');
       // Begin the table
       $return = '<table class="tl_optionwizard" id="ctrl_' . $this->strId . '">
 <thead>
   <tr>
     <th>' . $GLOBALS['TL_LANG']['MSC']['ow_value'] . '</th>
     <th>' . $GLOBALS['TL_LANG']['MSC']['ow_label'] . '</th>
     <th>&nbsp;</th>
     <th>&nbsp;</th>
     <th>&nbsp;</th>
   </tr>
 </thead>
 <tbody class="sortable" data-tabindex="' . $tabindex . '">';
       // Add fields
       for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
           $return .= '
   <tr>
     <td><input type="text" name="' . $this->strId . '[' . $i . '][value]" id="' . $this->strId . '_value_' . $i . '" class="tl_text_2" tabindex="' . $tabindex++ . '" value="' . specialchars($this->varValue[$i]['value']) . '"></td>
     <td><input type="text" name="' . $this->strId . '[' . $i . '][label]" id="' . $this->strId . '_label_' . $i . '" class="tl_text_2" tabindex="' . $tabindex++ . '" value="' . specialchars($this->varValue[$i]['label']) . '"></td>
     <td><input type="checkbox" name="' . $this->strId . '[' . $i . '][default]" id="' . $this->strId . '_default_' . $i . '" class="fw_checkbox" tabindex="' . $tabindex++ . '" value="1"' . ($this->varValue[$i]['default'] ? ' checked="checked"' : '') . '> <label for="' . $this->strId . '_default_' . $i . '">' . $GLOBALS['TL_LANG']['MSC']['ow_default'] . '</label></td>
     <td><input type="checkbox" name="' . $this->strId . '[' . $i . '][group]" id="' . $this->strId . '_group_' . $i . '" class="fw_checkbox" tabindex="' . $tabindex++ . '" value="1"' . ($this->varValue[$i]['group'] ? ' checked="checked"' : '') . '> <label for="' . $this->strId . '_group_' . $i . '">' . $GLOBALS['TL_LANG']['MSC']['ow_group'] . '</label></td>';
           // Add row buttons
           $return .= '
     <td style="white-space:nowrap; padding-left:3px">';
           foreach ($arrButtons as $button) {
               $class = $button == 'up' || $button == 'down' ? ' class="button-move"' : '';
               if ($button == 'drag') {
                   $return .= \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG']['MSC']['move']) . '"');
               } else {
                   $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '"' . $class . ' title="' . specialchars($GLOBALS['TL_LANG']['MSC']['ow_' . $button]) . '" onclick="Backend.optionsWizard(this,\'' . $button . '\',\'ctrl_' . $this->strId . '\');return false">' . \Image::getHtml($button . '.gif', $GLOBALS['TL_LANG']['MSC']['ow_' . $button]) . '</a> ';
               }
           }
           $return .= '</td>
   </tr>';
       }
       // Store the tab index
       \Cache::set('tabindex', $tabindex);
       return $return . '
 </tbody>
 </table>';
   }
Exemplo n.º 24
0
 public function widgetdeleted($idwidget)
 {
     $deleted = false;
     foreach ($this->items as &$viewitem) {
         unset($sidebar);
         foreach ($viewitem['sidebars'] as &$sidebar) {
             for ($i = count($sidebar) - 1; $i >= 0; $i--) {
                 if ($idwidget == $sidebar[$i]['id']) {
                     array_delete($sidebar, $i);
                     $deleted = true;
                 }
             }
         }
     }
     if ($deleted) {
         $this->save();
     }
 }
Exemplo n.º 25
0
 private function extract_bounds_from_options(&$options)
 {
     if (array_key_exists('bounds', $options)) {
         $bounds = $options['bounds'];
         array_delete($options, 'bounds');
         return Bounds::normalize($bounds);
     }
     return null;
 }
Exemplo n.º 26
0
   /**
    * Generate the widget and return it as string
    * @return string
    */
   public function generate()
   {
       $arrButtons = array('copy', 'up', 'down', 'delete');
       $strCommand = 'cmd_' . $this->strField;
       // Change the order
       if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
           $this->import('Database');
           switch ($this->Input->get($strCommand)) {
               case 'copy':
                   $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid'));
                   break;
               case 'up':
                   $this->varValue = array_move_up($this->varValue, $this->Input->get('cid'));
                   break;
               case 'down':
                   $this->varValue = array_move_down($this->varValue, $this->Input->get('cid'));
                   break;
               case 'delete':
                   $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                   break;
           }
           $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
           $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
       }
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || count($this->varValue) < 1) {
           $this->varValue = array('');
       }
       $tabindex = 0;
       $return .= '<ul id="ctrl_' . $this->strId . '" class="tl_listwizard">';
       // Add input fields
       for ($i = 0; $i < count($this->varValue); $i++) {
           $return .= '
   <li><input type="text" name="' . $this->strId . '[]" class="tl_text" tabindex="' . ++$tabindex . '" value="' . specialchars($this->varValue[$i]) . '"' . $this->getAttributes() . '> ';
           // Add buttons
           foreach ($arrButtons as $button) {
               $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['lw_' . $button]) . '" onclick="Backend.listWizard(this, \'' . $button . '\', \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG']['MSC']['lw_' . $button], 'class="tl_listwizard_img"') . '</a> ';
           }
           $return .= '</li>';
       }
       return $return . '
 </ul>';
   }
Exemplo n.º 27
0
    /**
     * Generate the widget and return it as string
     * @return string
     */
    public function generate()
    {
        $blnLanguage = false;
        $this->import('Database');
        // Merge parent record data
        if ($_SESSION['BE_DATA']['language'][$this->strTable][$this->currentRecord] != '') {
            $blnLanguage = true;
            $objParent = $this->Database->execute("SELECT * FROM {$this->strTable} WHERE id={$this->currentRecord}");
            $arrParent = deserialize($objParent->{$this->strField});
            $this->import('Isotope');
            $this->varValue = $this->Isotope->mergeMediaData($this->varValue, $arrParent);
        }
        $GLOBALS['TL_CSS'][] = TL_PLUGINS_URL . 'plugins/mediabox/' . MEDIABOX . '/css/mediaboxAdvBlack21.css|screen';
        $GLOBALS['TL_JAVASCRIPT'][] = TL_PLUGINS_URL . 'plugins/mediabox/' . MEDIABOX . '/js/mediabox.js';
        $GLOBALS['TL_JAVASCRIPT'][] = TL_PLUGINS_URL . 'system/modules/isotope/html/mediabox_init.js';
        $arrButtons = array('up', 'down', 'delete');
        $strCommand = 'cmd_' . $this->strField;
        // Change the order
        if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
            switch ($this->Input->get($strCommand)) {
                case 'up':
                    $this->varValue = array_move_up($this->varValue, $this->Input->get('cid'));
                    break;
                case 'down':
                    $this->varValue = array_move_down($this->varValue, $this->Input->get('cid'));
                    break;
                case 'delete':
                    $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                    break;
            }
            $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
            $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
        }
        $upload = sprintf('<h3><label for="ctrl_%s_upload">%s</label></h3><p><input type="file" name="%s" id="ctrl_%s_upload" class="upload%s"></p>', $this->strId, $GLOBALS['TL_LANG']['MSC']['mmUpload'], $this->strName, $this->strId, strlen($this->strClass) ? ' ' . $this->strClass : '');
        $return = '<div id="ctrl_' . $this->strId . '">';
        if (!is_array($this->varValue) || !count($this->varValue)) {
            return $return . $GLOBALS['TL_LANG']['MSC']['mmNoUploads'] . $upload . '</div>';
        }
        // Add label and return wizard
        $return .= '<table class="tl_mediamanager">
  <thead>
  <tr>
    <td class="col_0 col_first">' . $GLOBALS['TL_LANG'][$this->strTable]['mmSrc'] . '</td>
    <td class="col_1">' . $GLOBALS['TL_LANG'][$this->strTable]['mmAlt'] . ' / ' . $GLOBALS['TL_LANG'][$this->strTable]['mmLink'] . '</td>
    <td class="col_2">' . $GLOBALS['TL_LANG'][$this->strTable]['mmDesc'] . '</td>
    <td class="col_3">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslate'] . '</td>
    <td class="col_4 col_last">&nbsp;</td>
  </tr>
  </thead>
  <tbody>';
        // Add input fields
        for ($i = 0; $i < count($this->varValue); $i++) {
            $strFile = 'isotope/' . strtolower(substr($this->varValue[$i]['src'], 0, 1)) . '/' . $this->varValue[$i]['src'];
            if (!is_file(TL_ROOT . '/' . $strFile)) {
                continue;
            }
            $objFile = new File($strFile);
            if ($objFile->isGdImage) {
                $strPreview = $this->getImage($strFile, 50, 50, 'box');
            } else {
                $strPreview = 'system/themes/' . $this->getTheme() . '/images/' . $objFile->icon;
            }
            $strTranslateText = $blnLanguage && $this->varValue[$i]['translate'] != 'all' ? ' disabled="disabled"' : '';
            $strTranslateNone = $blnLanguage && !$this->varValue[$i]['translate'] ? ' disabled="disabled"' : '';
            $return .= '
  <tr>
    <td class="col_0 col_first"><input type="hidden" name="' . $this->strName . '[' . $i . '][src]" value="' . specialchars($this->varValue[$i]['src']) . '"><a href="' . $strFile . '" rel="lightbox"><img src="' . $strPreview . '" alt="' . specialchars($this->varValue[$i]['src']) . '"></a></td>
    <td class="col_1"><input type="text" class="tl_text_2" name="' . $this->strName . '[' . $i . '][alt]" value="' . specialchars($this->varValue[$i]['alt']) . '"' . $strTranslateNone . '><br><input type="text" class="tl_text_2" name="' . $this->strName . '[' . $i . '][link]" value="' . specialchars($this->varValue[$i]['link']) . '"' . $strTranslateText . '></td>
    <td class="col_2"><textarea name="' . $this->strName . '[' . $i . '][desc]" cols="40" rows="3" class="tl_textarea"' . $strTranslateNone . ' >' . specialchars($this->varValue[$i]['desc']) . '</textarea></td>
    <td class="col_3">
    	' . ($blnLanguage ? '<input type="hidden" name="' . $this->strName . '[' . $i . '][translate]" value="' . $this->varValue[$i]['translate'] . '"' : '') . '
    	<fieldset class="radio_container">
	    	<span>
	    		<input id="' . $this->strName . '_' . $i . '_translate_none" name="' . $this->strName . '[' . $i . '][translate]" type="radio" class="tl_radio" value=""' . $this->optionChecked('', $this->varValue[$i]['translate']) . ($blnLanguage ? ' disabled="disabled"' : '') . '>
	    		<label for="' . $this->strName . '_' . $i . '_translate_none" title="' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateNone'][1] . '">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateNone'][0] . '</label></span>
	    	<span>
	    		<input id="' . $this->strName . '_' . $i . '_translate_text" name="' . $this->strName . '[' . $i . '][translate]" type="radio" class="tl_radio" value="text"' . $this->optionChecked('text', $this->varValue[$i]['translate']) . ($blnLanguage ? ' disabled="disabled"' : '') . '>
	    		<label for="' . $this->strName . '_' . $i . '_translate_text" title="' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateText'][1] . '">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateText'][0] . '</label></span>
	    	<span>
	    		<input id="' . $this->strName . '_' . $i . '_translate_all" name="' . $this->strName . '[' . $i . '][translate]" type="radio" class="tl_radio" value="all"' . $this->optionChecked('all', $this->varValue[$i]['translate']) . ($blnLanguage ? ' disabled="disabled"' : '') . '>
	    		<label for="' . $this->strName . '_' . $i . '_translate_all" title="' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateAll'][1] . '">' . $GLOBALS['TL_LANG'][$this->strTable]['mmTranslateAll'][0] . '</label></span>
    	</fieldset>
    </td>
    <td class="col_4 col_last">';
            foreach ($arrButtons as $button) {
                if ($button == 'delete' && $blnLanguage && $this->varValue[$i]['translate'] != 'all') {
                    continue;
                }
                $return .= '<a href="' . $this->addToUrl('&amp;' . $strCommand . '=' . $button . '&amp;cid=' . $i . '&amp;id=' . $this->currentRecord) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button]) . '" onclick="Isotope.mediaManager(this, \'' . $button . '\',  \'ctrl_' . $this->strId . '\'); return false;">' . $this->generateImage($button . '.gif', $GLOBALS['TL_LANG'][$this->strTable]['wz_' . $button], 'class="tl_listwizard_img"') . '</a> ';
            }
            $return .= '</td>
  </tr>';
        }
        return $return . '
  </tbody>
  </table>' . $upload . '</div>';
    }
Exemplo n.º 28
0
 /**
  * Clean url fragments from language and auto_item
  *
  * @param $arrFragments
  *
  * @return array
  */
 private function mapUrlFragments($arrFragments)
 {
     // Delete auto_item
     if (\Config::get('useAutoItem') && $arrFragments[1] === 'auto_item') {
         $arrFragments = array_delete($arrFragments, 1);
     }
     // Delete language if first part of url
     if (\Config::get('i18nl10n_urlParam') === 'url') {
         $arrFragments = array_delete($arrFragments, 0);
     } elseif (\Config::get('i18nl10n_urlParam') === 'alias' && !\Config::get('disableAlias')) {
         $lastIndex = count($arrFragments) - 1;
         $strRegex = '@^([_\\-\\pL\\pN\\.]*(?=\\.))?\\.?([a-z]{2})$@u';
         // last element should contain language info
         if (preg_match($strRegex, $arrFragments[$lastIndex], $matches)) {
             $arrFragments[$lastIndex] = $matches[1];
         }
     }
     return $arrFragments;
 }
Exemplo n.º 29
0
 private function joinitems(array $items, array $subitems)
 {
     if (count($subitems) == 0) {
         return $items;
     }
     if (count($items) > 0) {
         //delete copies
         for ($i = count($items) - 1; $i >= 0; $i--) {
             $id = $items[$i]['id'];
             foreach ($subitems as $subitem) {
                 if ($id == $subitem['id']) {
                     array_delete($items, $i);
                 }
             }
         }
     }
     //join
     foreach ($subitems as $item) {
         $count = count($items);
         $order = $item['order'];
         if ($order < 0 || $order >= $count) {
             $items[] = $item;
         } else {
             array_insert($items, $item, $order);
         }
     }
     return $items;
 }
    /**
     * Generate the widget and return it as string
     * @return string
     */
    public function generate()
    {
        // load the callback data if there's any (do not do this in __set() already because then we don't have access to currentRecord)
        if (is_array($this->arrCallback)) {
            $this->import($this->arrCallback[0]);
            $this->columnFields = $this->{$this->arrCallback[0]}->{$this->arrCallback[1]}($this);
        }
        // use BE script in FE for now
        $GLOBALS['TL_JAVASCRIPT']['mcw'] = $GLOBALS['TL_CONFIG']['debugMode'] ? 'system/modules/multicolumnwizard/html/js/multicolumnwizard_be_src.js' : 'system/modules/multicolumnwizard/html/js/multicolumnwizard_be.js';
        $GLOBALS['TL_CSS']['mcw'] = $GLOBALS['TL_CONFIG']['debugMode'] ? 'system/modules/multicolumnwizard/html/css/multicolumnwizard_src.css' : 'system/modules/multicolumnwizard/html/css/multicolumnwizard.css';
        $this->strCommand = 'cmd_' . $this->strField;
        // Change the order
        if ($this->Input->get($this->strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) {
            switch ($this->Input->get($this->strCommand)) {
                case 'copy':
                    $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid'));
                    break;
                case 'up':
                    $this->varValue = array_move_up($this->varValue, $this->Input->get('cid'));
                    break;
                case 'down':
                    $this->varValue = array_move_down($this->varValue, $this->Input->get('cid'));
                    break;
                case 'delete':
                    $this->varValue = array_delete($this->varValue, $this->Input->get('cid'));
                    break;
            }
            // Save in File
            if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'File') {
                $this->Config->update(sprintf("\$GLOBALS['TL_CONFIG']['%s']", $this->strField), serialize($this->varValue));
                // Reload the page
                $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
            } else {
                if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'] == 'Table') {
                    if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'])) {
                        $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'];
                        // If less than 3.X, we must load the class by hand.
                        if (version_compare(VERSION, '3.0', '<')) {
                            require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer);
                        }
                        $dc = new $dataContainer($this->strTable);
                        $dc->field = $objWidget->id;
                        $dc->inputName = $objWidget->id;
                        foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['save_callback'] as $callback) {
                            $this->import($callback[0]);
                            $this->{$callback}[0]->{$callback}[1](serialize($this->varValue), $dc);
                        }
                    } else {
                        $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?")->execute(serialize($this->varValue), $this->currentRecord);
                    }
                    // Reload the page
                    $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($this->strCommand, '/') . '=[^&]*/i', '', $this->Environment->request)));
                } else {
                    // What to do here?
                }
            }
        }
        $arrUnique = array();
        $arrDatepicker = array();
        $arrColorpicker = array();
        $arrTinyMCE = array();
        $arrHeaderItems = array();
        foreach ($this->columnFields as $strKey => $arrField) {
            // Store unique fields
            if ($arrField['eval']['unique']) {
                $arrUnique[] = $strKey;
            }
            // Store date picker fields
            if ($arrField['eval']['datepicker']) {
                $arrDatepicker[] = $strKey;
            }
            // Store color picker fields
            if ($arrField['eval']['colorpicker']) {
                $arrColorpicker[] = $strKey;
            }
            // Store tiny mce fields
            if ($arrField['eval']['rte'] && strncmp($arrField['eval']['rte'], 'tiny', 4) === 0) {
                foreach ($this->varValue as $row => $value) {
                    $tinyId = 'ctrl_' . $this->strField . '_row' . $row . '_' . $strKey;
                    $GLOBALS['TL_RTE']['tinyMCE'][$tinyId] = array('id' => $tinyId, 'file' => 'tinyMCE', 'type' => null);
                }
                $arrTinyMCE[] = $strKey;
            }
            if ($arrField['inputType'] == 'hidden') {
                continue;
            }
        }
        $intNumberOfRows = max(count($this->varValue), 1);
        // always show the minimum number of rows if set
        if ($this->minCount && $intNumberOfRows < $this->minCount) {
            $intNumberOfRows = $this->minCount;
        }
        $arrItems = array();
        $arrHiddenHeader = array();
        // Add input fields
        for ($i = 0; $i < $intNumberOfRows; $i++) {
            $this->activeRow = $i;
            $strHidden = '';
            // Walk every column
            foreach ($this->columnFields as $strKey => $arrField) {
                $strWidget = '';
                $blnHiddenBody = false;
                if ($arrField['eval']['hideHead'] == true) {
                    $arrHiddenHeader[$strKey] = true;
                }
                // load row specific data (useful for example for default values in different rows)
                if (isset($this->arrRowSpecificData[$i][$strKey])) {
                    $arrField = array_merge($arrField, $this->arrRowSpecificData[$i][$strKey]);
                }
                $objWidget = $this->initializeWidget($arrField, $i, $strKey, $this->varValue[$i][$strKey]);
                // load errors if there are any
                if (!empty($this->arrWidgetErrors[$strKey][$i])) {
                    foreach ($this->arrWidgetErrors[$strKey][$i] as $strErrorMsg) {
                        $objWidget->addError($strErrorMsg);
                    }
                }
                if ($objWidget === null) {
                    continue;
                } elseif (is_string($objWidget)) {
                    $strWidget = $objWidget;
                } elseif ($arrField['inputType'] == 'hidden') {
                    $strHidden .= $objWidget->generate();
                    continue;
                } elseif ($arrField['eval']['hideBody'] == true || $arrField['eval']['hideHead'] == true) {
                    if ($arrField['eval']['hideBody'] == true) {
                        $blnHiddenBody = true;
                    }
                    $strWidget = $objWidget->parse();
                } else {
                    $datepicker = '';
                    $colorpicker = '';
                    $tinyMce = '';
                    // Datepicker
                    if ($arrField['eval']['datepicker']) {
                        $rgxp = $arrField['eval']['rgxp'];
                        $format = $GLOBALS['TL_CONFIG'][$rgxp . 'Format'];
                        switch ($rgxp) {
                            case 'datim':
                                $time = ",\n      timePicker:true";
                                break;
                            case 'time':
                                $time = ",\n      timePickerOnly:true";
                                break;
                            default:
                                $time = '';
                                break;
                        }
                        $datepicker = ' <img src="system/modules/multicolumnwizard/html/img/datepicker.gif" width="20" height="20" alt="" id="toggle_' . $objWidget->id . '" style="vertical-align:-6px;">
                          <script>
							  window.datepicker_' . $this->strName . '_' . $strKey . ' = new DatePicker(\'#ctrl_' . $objWidget->id . '\', {
							  allowEmpty:true,
							  toggleElements:\'#toggle_' . $objWidget->id . '\',
							  pickerClass:\'datepicker_dashboard\',
							  format:\'' . $format . '\',
							  inputOutputFormat:\'' . $format . '\',
							  positionOffset:{x:130,y:-185}' . $time . ',
							  startDay:' . $GLOBALS['TL_LANG']['MSC']['weekOffset'] . ',
							  days:[\'' . implode("','", $GLOBALS['TL_LANG']['DAYS']) . '\'],
							  dayShort:' . $GLOBALS['TL_LANG']['MSC']['dayShortLength'] . ',
							  months:[\'' . implode("','", $GLOBALS['TL_LANG']['MONTHS']) . '\'],
							  monthShort:' . $GLOBALS['TL_LANG']['MSC']['monthShortLength'] . '
                          });
                          </script>';
                        $datepicker = $this->getMcWDatePickerString($objWidget->id, $strKey, $rgxp);
                        /* $datepicker = '<script>
                           window.addEvent(\'domready\', function() {
                           ' . sprintf($this->getDatePickerString(), 'ctrl_' . $objWidget->strId) . '
                           });
                           </script>'; */
                    }
                    // Color picker
                    if ($arrField['eval']['colorpicker']) {
                        // Support single fields as well (see #5240)
                        //$strKey = $arrData['eval']['multiple'] ? $this->strField . '_0' : $this->strField;
                        $colorpicker = ' ' . \Image::getHtml('pickcolor.gif', $GLOBALS['TL_LANG']['MSC']['colorpicker'], 'style="vertical-align:top;cursor:pointer" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['colorpicker']) . '" id="moo_' . $objWidget->id . '"') . '
			  <script>
				window.addEvent("domready", function() {
				  new MooRainbow("moo_' . $objWidget->id . '", {
					id: "ctrl_' . $objWidget->id . '",
					startColor: ((cl = $("ctrl_' . $objWidget->id . '").value.hexToRgb(true)) ? cl : [255, 0, 0]),
					imgPath: "assets/mootools/colorpicker/' . $GLOBALS['TL_ASSETS']['COLORPICKER'] . '/images/",
					onComplete: function(color) {
					  $("ctrl_' . $objWidget->id . '").value = color.hex.replace("#", "");
					}
				  });
				});
			  </script>';
                    }
                    // Tiny MCE
                    if ($arrField['eval']['rte'] && strncmp($arrField['eval']['rte'], 'tiny', 4) === 0) {
                        $tinyMce = $this->getMcWTinyMCEString($objWidget->id, $arrField);
                        $arrField['eval']['tl_class'] .= ' tinymce';
                    }
                    // Add custom wizard
                    if (is_array($arrField['wizard'])) {
                        $wizard = '';
                        $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$this->strTable]['config']['dataContainer'];
                        // If less than 3.X, we must load the class by hand.
                        if (version_compare(VERSION, '3.0', '<')) {
                            require_once sprintf('%s/system/drivers/%s.php', TL_ROOT, $dataContainer);
                        }
                        $dc = new $dataContainer($this->strTable);
                        $dc->field = $objWidget->id;
                        $dc->inputName = $objWidget->id;
                        $dc->value = $objWidget->value;
                        foreach ($arrField['wizard'] as $callback) {
                            $this->import($callback[0]);
                            $wizard .= $this->{$callback}[0]->{$callback}[1]($dc, $objWidget);
                        }
                        $objWidget->wizard = $wizard;
                    }
                    $strWidget = $objWidget->parse() . $datepicker . $colorpicker . $tinyMce;
                }
                // Build array of items
                if ($arrField['eval']['columnPos'] != '') {
                    $arrItems[$i][$objWidget->columnPos]['entry'] .= $strWidget;
                    $arrItems[$i][$objWidget->columnPos]['valign'] = $arrField['eval']['valign'];
                    $arrItems[$i][$objWidget->columnPos]['tl_class'] = $arrField['eval']['tl_class'];
                    $arrItems[$i][$objWidget->columnPos]['hide'] = $blnHiddenBody;
                } else {
                    $arrItems[$i][$strKey] = array('entry' => $strWidget, 'valign' => $arrField['eval']['valign'], 'tl_class' => $arrField['eval']['tl_class'], 'hide' => $blnHiddenBody);
                }
            }
        }
        $strOutput = '';
        if ($this->blnTableless) {
            $strOutput = $this->generateDiv($arrUnique, $arrDatepicker, $arrColorpicker, $strHidden, $arrItems, $arrHiddenHeader);
        } else {
            if ($this->columnTemplate != '') {
                $strOutput = $this->generateTemplateOutput($arrUnique, $arrDatepicker, $arrColorpicker, $strHidden, $arrItems, $arrHiddenHeader);
            } else {
                $strOutput = $this->generateTable($arrUnique, $arrDatepicker, $arrColorpicker, $strHidden, $arrItems, $arrHiddenHeader);
            }
        }
        return $strOutput;
    }