public function summary($field, $data, $object) { if (!($structure = FW4_Structure::get_object_structure('user', false))) { return ''; } $row = where('id', intval($data[strval($field['name'])]))->get_row('user'); if (!$row) { return ''; } if (!($titlefield = reset($structure->xpath('string')))) { return false; } if (isset($field['display'])) { $displayvalue = $field['display']; preg_match_all('/\\[([a-z0-9\\_]+)\\]/is', $field['display'], $matches, PREG_SET_ORDER); foreach ($matches as $match) { $displayvalue = str_ireplace($match[0], $row[$match[1]], $displayvalue); } return $displayvalue; } else { return $row[strval($titlefield['name'])]; } }
private function _delete($structure, $stack, $data) { $ids = $data->ids(); if (count($ids)) { if (isset($structure['archived']) && $structure['name'] != '_versions') { where('id IN %$', $ids)->delete($structure['stack'] . '>_versions'); } // Remove from search index where('object_id IN %$ AND object_name = %s', $ids, $stack)->delete('_search_index'); $types = FW4_Type_Manager::get_instance(); foreach ($structure->children() as $type => $child) { if ($type == 'object' && strval($child['name']) != '_versions' && !isset($child['child'])) { $ids = array(); $childname = strval($child['name']); foreach ($data as $row) { $ids[] = $row->id; } if (count($ids)) { $childstructure = FW4_Structure::get_object_structure($stack . '>' . $childname); $childdata = where($structure['name'] . '_id IN %$', $ids)->get($childstructure['path']); $this->_delete($childstructure, $childstructure['path'], $childdata); } } else { if ($type == 'recursive' && strval($child['name']) != '_versions') { $ids = array(); foreach ($data as $row) { $ids[] = $row->id; } if (count($ids)) { $childdata = where('parent_id IN %$', $ids)->get($structure['path']); $this->_delete($structure, $structure['path'], $childdata); } } else { if (isset($child['type_name']) && ($type_obj = $types->get_type(strval($child['type_name'])))) { $type_obj->deleted($child, $data); } } } } if (isset($structure['type_name']) && ($type_obj = $types->get_type(strval($structure['type_name'])))) { $type_obj->deleted($structure, $data); } foreach ($ids as $id) { if ($structure['name'] == '_versions') { $this->db->query('DELETE FROM `' . $structure['path'] . '` WHERE version_id = ' . $id); } else { $this->db->query('DELETE FROM `' . $structure['path'] . '` WHERE id = ' . $id); } } return true; } return false; }
private static function update_sorting_field($objectname) { if (!($structure = FW4_Structure::get_object_structure($objectname))) { return false; } $db = FW4_Db::get_instance(); $db->query('SELECT @row:=0;'); $db->query('UPDATE `' . $structure['path'] . '` SET _sort_order = (@row:=@row+1) ORDER BY _sort_order, id DESC;'); if (isset($structure['archived']) && strval($structure['name']) != '_versions') { $db->query('UPDATE `' . $structure['path'] . '>_versions` versions JOIN `' . $structure['path'] . '` origtable ON origtable.id = versions.id SET versions._sort_order = origtable._sort_order WHERE versions.version_id IN (SELECT * FROM (SELECT MAX(version_id) FROM `' . $structure['path'] . '>_versions` GROUP BY id) as version_ids)'); } }
public function function_ajax_autocomplete($field, $object, $data) { $query = limit(5)->where('id != %d', intval($_POST['currentid'])); $searchable_fields = array(); $source = isset($field['source']) ? strval($field['source']) : $object['stack']; if (!($structure = FW4_Structure::get_object_structure($source, false))) { return false; } $possible_searchable_fields = $structure->xpath('string'); $titlefield = reset($possible_searchable_fields); $titlefield = strval($titlefield['name']); foreach ($structure->xpath('string') as $searchable_field) { $searchable_fields[] = strval($searchable_field['name']); } $search_where_strings = array(); foreach (explode(' ', $_POST['search']) as $keyword) { $search_where_strings[] = 'CONCAT(IFNULL(`' . implode('`,""),IFNULL(`', $searchable_fields) . '`,"")) LIKE ' . $query->escape('*' . $keyword . '*'); } $query->where(implode(' AND ', $search_where_strings)); if (isset($_POST['otherids']) && is_array($_POST['otherids']) && count($_POST['otherids'])) { $query->where('id NOT IN %$', $_POST['otherids']); } $result = array(); foreach ($query->get($source) as $row) { $result[] = array('id' => $row->id, 'title' => $row->{$titlefield}); } echo json_encode($result); }
public function get_source_rows($name, $field, $id = false) { if ($id) { return where('id = %d', $id)->get($name); } if (isset($field['where'])) { $query = new Query(); $path = explode('>', FW4_Admin::$parent_structure['path']); $whereval = strval($field['where']); if (preg_match_all('/\\[(.*?)\\]/is', $whereval, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $parent_item = false; $current_item = FW4_Admin::$current_item; foreach (explode('.', $match[1]) as $part) { if ($part == 'parent') { array_pop($path); if ($parent_item === false) { $parent_item = FW4_Admin::$parent_item; } else { $parent_item = $parent_item->parent(); } } else { if (!$parent_item && !$current_item) { return false; } $data = $parent_item ? $parent_item : $current_item; $structure = FW4_Structure::get_object_structure(implode('>', $path), false); $other_field = $structure->xpath('*[@name="' . addslashes($part) . '"]'); if (is_array($other_field)) { $other_field = reset($other_field); } if ($other_field && $other_field->getName() == 'choice') { if (isset($other_field['multiple'])) { $ids = $data->{$part}->ids(); if (!count($ids)) { $ids[] = 0; } $whereval = str_replace($match[0], '(' . implode(',', $ids) . ')', $whereval); } else { $fieldname = $part . '_id'; if (!isset($data->{$fieldname})) { return false; } $whereval = str_replace($match[0], $data->{$fieldname}, $whereval); } } else { if (!property_exists($data, $part)) { return false; } $whereval = str_replace($match[0], is_null($data->{$part}) ? 'NULL' : $data->{$part}, $whereval); } } } } } if (preg_match_all('/(\\S+)\\s+contains\\s+(\\S+)/is', $whereval, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $structure = FW4_Structure::get_object_structure($name, false); $other_field = $structure->xpath('*[@name="' . addslashes($match[1]) . '"]'); if (is_array($other_field)) { $other_field = reset($other_field); } if (!isset($other_field['multiple'])) { throw new Exception('"contains" only possible on choice with multiple attribute'); } if (!$other_field) { return false; } $query->join($structure['path'] . '>' . $other_field['name'], $other_field['name'] . '.' . $structure['name'] . '_id = ' . $structure['name'] . '.id'); $whereval = str_replace($match[0], $other_field['name'] . '.' . $other_field['name'] . ' = ' . $match[2], $whereval); } } return $query->where($whereval)->get($name); } if (!isset(self::$cache[$name])) { self::$cache[$name] = get($name); } return self::$cache[$name]; }
public function print_field($field, $data, $object) { $source_rows = self::get_source_rows(strval($field['source']), $field); if ($source_rows === false) { return false; } $source_structure = FW4_Structure::get_object_structure($field['source'], false); $source_title = isset($source_structure['title']) ? $source_structure['title'] : 'aandachtspunten'; $fieldname = strval($field['name']); $imagefieldname = $fieldname . '_image'; $orig_filename = $imagefieldname . '_orig_filename'; $alt = $imagefieldname . '_alt'; if (isset($field['is_viewing_version']) && $field['is_viewing_version']) { return false; } $options = ''; if (isset($field['source'])) { if (!($structure = FW4_Structure::get_object_structure(strval($field['source']), false))) { return false; } $titlefields = $structure->xpath('string'); if (!($titlefield = reset($titlefields))) { $titlefields = $structure->xpath('number'); if (!($titlefield = reset($titlefields))) { return false; } } $titlefield = strval($titlefield['name']); $group_value = false; $group_is_choice = false; $group_values = array(); if (isset($field['group_by'])) { $group_by_field = reset($structure->xpath('*[@name="' . strval($field['group_by']) . '"]')); if ($group_by_field->getName() == "choice") { $group_is_choice = true; foreach ($group_by_field->children() as $group_child) { $value = strval($group_child); if (isset($group_child['value'])) { $value = strval($group_child['value']); } $group_values[$value] = strval($group_child); } } } else { if (isset($field['optgroup'])) { if (!($parent_structure = FW4_Structure::get_object_structure(substr($structure['path'], 0, strrpos($structure['path'], '>')), true))) { return false; } $parenttitlefields = $parent_structure->xpath('string'); if (!($parenttitlefield = reset($parenttitlefields))) { $parenttitlefields = $parent_structure->xpath('number'); if (!($parenttitlefields = reset($parenttitlefields))) { return false; } } $parenttitlefield = strval($parenttitlefield['name']); $source_rows = $source_rows->to_array(); usort($source_rows, function ($a, $b) use($parenttitlefield) { if ($a->parent()->{$parenttitlefield} == $b->parent()->{$parenttitlefield}) { return 0; } return $a->parent()->{$parenttitlefield} < $b->parent()->{$parenttitlefield} ? -1 : 1; }); } } foreach ($source_rows as $child) { $value = $child->id; if (isset($field['group_by']) && ($group_field = strval($field['group_by']) && $child->{$group_field} != $group_value)) { if ($group_value) { $options .= '</optgroup>'; } $group_value = $actual_group_value = $child[strval($field['group_by'])]; if ($group_is_choice) { $actual_group_value = $group_values[$group_value]; } $options .= '<optgroup label="' . $actual_group_value . '">'; } else { if (isset($field['optgroup']) && $child->parent()->{$parenttitlefield} != $group_value) { if ($group_value) { $options .= '</optgroup>'; } $group_value = $child->parent()->{$parenttitlefield}; $options .= '<optgroup label="' . $group_value . '">'; } } $options .= '<option value="' . $value . '">'; if (isset($field['format'])) { $displayvalue = $field['format']; preg_match_all('/\\[([a-z0-9\\_]+)\\]/is', $field['format'], $matches, PREG_SET_ORDER); foreach ($matches as $match) { $match_name = $match[1]; $displayvalue = str_ireplace($match[0], $child->{$match_name}, $displayvalue); } $options .= $displayvalue; } else { $options .= htmlentities($child->{$titlefield}); } $options .= '</option>'; } if ($group_value) { $options .= '</optgroup>'; } } else { foreach ($field->children() as $child) { $value = isset($child['value']) ? $child['value'] : strval($child); $options .= '<option value="' . $value . '">' . strval($child) . '</option>'; } } $existing_areas = array(); if (isset($data->id) && $data->id) { $areas_fieldname = $field['name'] . '_area'; $filename_fieldname = $field['name'] . '_image_filename'; if ($data->{$filename_fieldname}) { $width_field = $field['name'] . '_image_width'; $height_field = $field['name'] . '_image_height'; $canvas_width = $canvas_height = 800; if ($data->{$width_field} > $data->{$height_field}) { $canvas_height = $data->{$height_field} / $data->{$width_field} * $canvas_width; } else { $canvas_width = $data->{$width_field} / $data->{$height_field} * $canvas_height; } foreach ($data->{$areas_fieldname} as $existing_area) { $existing_areas[] = array('left' => $existing_area->topx * $canvas_width / 100, 'top' => $existing_area->topy * $canvas_height / 100, 'width' => $existing_area->bottomx * $canvas_width / 100 - $existing_area->topx * $canvas_width / 100, 'height' => $existing_area->bottomy * $canvas_height / 100 - $existing_area->topy * $canvas_height / 100, 'value' => intval($existing_area->value_id)); } } } ?> <div class="input" data-options="<?php echo str_replace('"', "'", $options); ?> "> <label<?php echo isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : ''; ?> ><?php echo isset($field['label']) ? $field['label'] : ucwords(preg_replace("/[^\\w-]+/i", " ", $field['name'])); ?> </label> <?php if (isset($data->id) && isset($data->{$imagefieldname}) && $data->{$imagefieldname}) { ?> <table class="list imagelist" width="100%" cellpadding="0" cellspacing="0"> <td width="0" valign="top"> <div style="background:url('<?php echo $data->{$imagefieldname}->cover(50, 50); ?> ')" class="image-thumbnail"></div> </td> <td width="100%"> <div><?php echo $data->{$orig_filename}; ?> </div> <div><a class="button areas" href="#" data-image="<?php echo $data->{$imagefieldname}->contain(800, 800); ?> ">Bepaal <?php echo strtolower($source_title); ?> </a></div> <input class="areas-input" type="hidden" name="<?php echo $field['name']; ?> -areas" value='<?php echo json_encode($existing_areas); ?> '/> </td> <?php if (!isset($field['required'])) { ?> <td width="0"><a class="delete" href="<?php echo $field['name']; ?> /delete/<?php echo $data->id; ?> " onclick="return confirm('<?php echo l(array('nl' => 'Bent u zeker dat u deze afbeelding wilt verwijderen?', 'fr' => 'Etes-vous sûr de vouloir supprimer cette image?', 'en' => 'Are you sure you want to delete this image?')); ?> ');"><img alt="<?php echo l(array('nl' => 'Verwijderen', 'fr' => 'Supprimer', 'en' => 'Delete')); ?> " title="<?php echo l(array('nl' => 'Verwijderen', 'fr' => 'Supprimer', 'en' => 'Delete')); ?> " src="<?php echo url(ADMINRESOURCES . 'images/del.png'); ?> " width="22" height="23"/></a></td><?php } ?> </table> <?php } ?> <div class="imagemaptypeuploader" data-fieldname="<?php echo $field['name']; ?> " data-title="<?php echo $source_title; ?> "></div> </div><?php }