$doc_id = $doc['id']; $idstring = isset($type) ? $type . '_' . ($revert_ids ? $id : $doc_id) : ''; ?> <div class="linked_elt" id="<?php echo $idstring; ?> "> <?php echo link_to($doc['name'], "@document_by_id_lang_slug?module={$module}&id=" . $doc_id . '&lang=' . $doc['culture'] . '&slug=' . make_slug($doc['name'])); if (isset($display_info) && $display_info) { echo '<div class="short_data">'; echo summarize_route($doc, true, true); } if (!isset($doc['parent_id']) and $show_link_to_delete) { echo c2c_link_to_delete_element($type, $revert_ids ? $id : $doc_id, $revert_ids ? $doc_id : $id, false, (int) $strict); } if (isset($display_info) && $display_info) { echo '</div>'; } ?> </div> <?php } ?> </div> </div><!-- one_kind_association --> <?php }
function format_book_data($books, $type, $main_id, $is_moderator = false) { $type_list = $type . '_list'; $module = 'books'; $main_module = c2cTools::Letter2Module(substr($type, 1, 1)); $strict = 1; $html = '<div class="association_content_inside_field">'; foreach ($books as $book) { $doc_id = $book['id']; $idstring = $type . '_' . $doc_id; $class = 'linked_elt'; $html .= '<div class="' . $class . '" id="' . $idstring . '">' . '<div class="assoc_img picto_' . $module . '" title="' . ucfirst(__($module)) . '"></div>'; $name = ucfirst($book['name']); $url = "@document_by_id_lang_slug?module={$module}&id={$doc_id}" . '&lang=' . $book['culture'] . '&slug=' . make_slug($book['name']); $html .= link_to($name, $url); if (isset($book['author']) && trim($book['author']) != '') { $html .= ' - ' . $book['author']; } if (isset($book['publication_date']) && trim($book['publication_date']) != '') { $html .= ' - ' . $book['publication_date']; } if ($is_moderator && $main_id && !c2cTools::mobileVersion()) { $html .= c2c_link_to_delete_element($type, $doc_id, $main_id, false, $strict); } $html .= '</div>'; } $html .= '</div>'; return $html; }
/** * Executes "associate current document with document" action * associated document can only be : articles, summits, books, huts, outings, routes, sites, users * ... restricted in security.yml to logged people */ public function executeAddAssociation() { $user = $this->getUser(); $user_id = $user->getId(); $is_moderator = $user->hasCredential(sfConfig::get('app_credentials_moderator')); // // Get parameters and check that association is allowed // // if session is time-over if (!$user_id) { return $this->ajax_feedback('Session is over. Please login again.'); } if (!$this->hasRequestParameter('document_id') || !$this->hasRequestParameter('main_id') || !$this->hasRequestParameter('document_module')) { return $this->ajax_feedback('Operation not allowed'); } $main_module = $this->getRequestParameter('module'); $main_id = $this->getRequestParameter('main_id'); $linked_module = $this->getRequestParameter('document_module'); $linked_id = $this->getRequestParameter('document_id'); $icon = $this->getRequestParameter('icon', ''); $div = $this->getRequestParameter('div', false); if ($linked_id == $main_id) { return $this->ajax_feedback('A document can not be linked to itself'); } switch ($linked_module) { case 'summits': $fields = array('id', 'is_protected', 'summit_type'); break; case 'routes': $fields = array('id', 'is_protected', 'duration'); break; case 'huts': $fields = array('id', 'is_protected', 'shelter_type'); break; case 'articles': $fields = array('id', 'is_protected', 'article_type'); break; case 'images': $fields = array('id', 'is_protected', 'image_type'); break; case 'documents': $fields = array('id', 'is_protected', 'module'); break; // FIXME prevent such case? // FIXME prevent such case? default: $fields = array('id', 'is_protected'); break; } $linked_document = Document::find(c2cTools::module2model($linked_module), $linked_id, $fields); $linked_module = $linked_module != 'documents' ? $linked_module : $linked_document->get('module'); if (!$linked_document) { return $this->ajax_feedback('Linked document does not exist'); } $type_modules = c2cTools::Modules2Type($main_module, $linked_module); if (empty($type_modules)) { return $this->ajax_feedback('Wrong association type'); } list($type, $swap, $main_module_new, $linked_module_new, $strict) = $type_modules; switch ($main_module) { case 'summits': $fields = array('id', 'is_protected', 'summit_type'); break; case 'routes': $fields = array('id', 'is_protected', 'duration'); break; case 'huts': $fields = array('id', 'is_protected', 'shelter_type'); break; case 'articles': $fields = array('id', 'is_protected', 'article_type'); break; case 'images': $fields = array('id', 'is_protected', 'image_type'); break; case 'documents': $fields = array('id', 'is_protected', 'module'); break; // FIXME prevent such case? // FIXME prevent such case? default: $fields = array('id', 'is_protected'); break; } $main_document = Document::find(c2cTools::module2model($main_module), $main_id, $fields); if (!$main_document) { return $this->ajax_feedback('Main document does not exist'); } if ($swap) { $main_document_new = $linked_document; $main_id_new = $linked_id; $linked_document_new = $main_document; $linked_id_new = $main_id; } else { $main_document_new = $main_document; $main_id_new = $main_id; $linked_document_new = $linked_document; $linked_id_new = $linked_id; } if ($linked_module_new == 'articles') { if (!$is_moderator) { if ($linked_document_new->get('article_type') == 2 && !Association::find($user_id, $linked_id_new, 'uc')) { return $this->ajax_feedback('You do not have the right to link a document to a personal article'); } if ($main_module_new == 'articles') { if ($main_document_new->get('article_type') == 2 && !Association::find($user_id, $main_id_new, 'uc')) { return $this->ajax_feedback('You do not have the right to link a document to a personal article'); } } if ($main_module_new == 'outings' && !Association::find($user_id, $main_id_new, 'uo')) { return $this->ajax_feedback('You do not have the right to link an article to another user outing'); } } if ($linked_document_new->get('article_type') != 2 && $type == 'uc') { return $this->ajax_feedback('An user can not be linked to a collaborative article'); } } if ($linked_module_new == 'images') { if ($main_document_new->get('is_protected') && !$is_moderator) { return $this->ajax_feedback('Document is protected'); } if (!$is_moderator) { if ($main_module_new == 'users' && $main_id_new != $user_id) { return $this->ajax_feedback('You do not have the right to link an image to another user profile'); } if ($main_module_new == 'outings' && !Association::find($user_id, $main_id_new, 'uo')) { return $this->ajax_feedback('You do not have the right to link an image to another user outing'); } if ($main_module_new == 'articles' && $main_document_new->get('article_type') == 2 && !Association::find($user_id, $main_id_new, 'uc')) { return $this->ajax_feedback('You do not have the right to link an image to a personal article'); } if ($main_module_new == 'images' && $main_document_new->get('image_type') == 2 && $document->getCreatorId() != $user_id) { return $this->ajax_feedback('You do not have the right to link an image to a personal image'); } } } if ($linked_module_new == 'outings') { if (!$is_moderator) { if ($main_module_new == 'users' && !Association::find($user_id, $linked_id_new, 'uo')) { return $this->ajax_feedback('You do not have the right to link an user to another user outing'); } if ($main_module_new == 'routes' && !Association::find($user_id, $linked_id_new, 'uo')) { return $this->ajax_feedback('You do not have the right to link a route to another user outing'); } if ($main_module_new == 'sites' && !Association::find($user_id, $linked_id_new, 'uo')) { return $this->ajax_feedback('You do not have the right to link a site to another user outing'); } } } if ($linked_module_new == 'xreports') { if (!$is_moderator) { if ($main_module_new == 'users' && !Association::find($user_id, $linked_id_new, 'ux')) { return $this->ajax_feedback('You do not have the right to link an user to another user xreport'); } if ($main_module_new == 'outings' && !Association::find($user_id, $linked_id_new, 'ux')) { return $this->ajax_feedback('You do not have the right to link an outing to another user xreport'); } if ($main_module_new == 'routes' && !Association::find($user_id, $linked_id_new, 'ux')) { return $this->ajax_feedback('You do not have the right to link a route to another user xreport'); } if ($main_module_new == 'sites' && !Association::find($user_id, $linked_id_new, 'ux')) { return $this->ajax_feedback('You do not have the right to link a site to another user xreport'); } } } if ($linked_module_new == 'huts') { if ($main_module_new == 'summits') { $associations = Association::findAllAssociations($linked_id_new, 'sh'); if (count($associations)) { return $this->ajax_feedback('This hut is already linked to a summit'); } } if ($main_module_new == 'parkings') { $associations_pp = Association::findAllAssociations($main_id_new, 'pp'); $associations_ph = Association::findAllAssociations($linked_id_new, 'ph'); foreach ($associations_pp as $a_pp) { foreach ($associations_ph as $a_ph) { if ($a_pp['main_id'] == $a_ph['main_id'] || $a_pp['linked_id'] == $a_ph['main_id']) { return $this->ajax_feedback('A parking can not be linked to a hut if a main/sub parking is already linked to it'); } } } } } if ($linked_module_new == 'routes') { if ($main_module_new == 'summits' && $main_document_new->get('summit_type') == 5 && $linked_document_new->get('duration') <= 2) { return $this->ajax_feedback('A raid summit can not be linked to a stage route'); } if ($main_module_new == 'huts' && ($main_document_new->get('shelter_type') == 5 || $main_document_new->get('shelter_type') == 6)) { return $this->ajax_feedback('A gite can not be linked to a route'); } if ($main_module_new == 'parkings') { $associations_pp = Association::findAllAssociations($main_id_new, 'pp'); $associations_pr = Association::findAllAssociations($linked_id_new, 'pr'); foreach ($associations_pp as $a_pp) { foreach ($associations_pr as $a_pr) { if ($a_pp['main_id'] == $a_pr['main_id'] || $a_pp['linked_id'] == $a_pr['main_id']) { return $this->ajax_feedback('A parking can not be linked to a route if a main/sub parking is already linked to it'); } } } } } if ($linked_module_new == 'sites') { if ($main_module_new == 'sites') { if (Association::countAllMain(array($linked_id_new), 'tt')) { return $this->ajax_feedback('A sub site can not be linked to more than one main site'); } } if ($main_module_new == 'summits') { if (Association::countAllMain(array($linked_id_new), 'st')) { return $this->ajax_feedback('A site can not be linked to more than one summit'); } if (Association::countAllMain(array($linked_id_new), 'tt')) { return $this->ajax_feedback('A summit can not be linked to a sub site'); } } if ($main_module_new == 'parkings') { $associations_pp = Association::findAllAssociations($main_id_new, 'pp'); $associations_pt = Association::findAllAssociations($linked_id_new, 'pt'); foreach ($associations_pp as $a_pp) { foreach ($associations_pt as $a_pt) { if ($a_pp['main_id'] == $a_pt['main_id'] || $a_pp['linked_id'] == $a_pt['main_id']) { return $this->ajax_feedback('A parking can not be linked to a site if a main/sub parking is already linked to it'); } } } } } if ($linked_module_new == 'summits') { if ($main_module_new == 'summits') { if ($main_document_new->get('summit_type') == 5 || $linked_document_new->get('summit_type') == 5) { return $this->ajax_feedback('A raid summit can not be linked to a real summit'); } if (Association::countAllMain(array($linked_id_new), 'ss')) { return $this->ajax_feedback('A sub summit can not be linked to more than one main summit'); } } } if ($linked_module_new == 'parkings') { if ($main_module_new == 'parkings') { if (Association::countAllMain(array($linked_id_new), 'pp')) { // return $this->ajax_feedback('A sub parking can not be linked to more than one main parking'); } } } if (Association::find($main_id_new, $linked_id_new, $type, false)) { return $this->ajax_feedback('The document is already linked to the current document'); } if ($linked_module_new == 'outings' && $main_module_new == 'users' && $linked_id != $user_id) { // send an email to warn the new user associated $email_recipient = UserPrivateData::find($linked_id)->getEmail(); $email_subject = $this->__('You have been associated to an outing'); $server = $_SERVER['SERVER_NAME']; $outing_link = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . "://{$server}/outings/{$main_id}"; $htmlBody = $this->__('You have been associated to outing %1% details', array('%1%' => '<a href="' . $outing_link . '">' . $outing_link . '</a>')); $mail = new sfMail(); $mail->setCharset('utf-8'); // definition of the required parameters $mail->setSender(sfConfig::get('app_outgoing_emails_sender')); $mail->setFrom(sfConfig::get('app_outgoing_emails_from')); $mail->addReplyTo(sfConfig::get('app_outgoing_emails_reply_to')); $mail->addAddress($email_recipient); $mail->setSubject($email_subject); $mail->setContentType('text/html'); $mail->setBody($htmlBody); $mail->setAltBody(strip_tags($htmlBody)); // send the email $mail->send(); } // Perform association $a = new Association(); $status = $a->doSaveWithValues($main_id_new, $linked_id_new, $type, $user_id); if (!$status) { return $this->ajax_feedback('Could not perform association'); } // cache clearing for current doc in every lang: $this->clearCache($main_module, $main_id, false, 'view'); $this->clearCache($linked_module, $linked_id, false, 'view'); // html to return sfLoader::loadHelpers(array('Tag', 'Url', 'Asset', 'AutoComplete')); $linked_document->setBestName($user->getPreferedLanguageList()); $bestname = $linked_document->get('name'); if ($linked_module == 'routes') { // in that case, output not only route name but also best summit name whose id has been passed (summit_id) $summit = explode(' [', $this->getRequestParameter('summits_name')); $bestname = $summit[0] . $this->__(' :') . ' ' . $bestname; } $linked_module_name = $icon ? $icon : $this->__($linked_module); $type_id_string = $type . '_' . $linked_id; $out = link_to($bestname, "@document_by_id?module={$linked_module}&id={$linked_id}"); if ($user->hasCredential('moderator')) { $out .= c2c_link_to_delete_element($type, $main_id_new, $linked_id_new, !$swap, $strict); } if ($div) { $icon_string = ''; if ($icon) { $icon_string = '<div class="assoc_img picto_' . $icon . '" title="' . ucfirst(__($icon)) . '">' . '<span>' . ucfirst(__($icon)) . __(' :') . '</span>' . '</div>'; } $out = '<div class="linked_elt" id="' . $type_id_string . '">' . $icon_string . $out . '</div>'; } else { $out = '<li id="' . $type_id_string . '">' . picto_tag('picto_' . $linked_module, $linked_module_name) . ' ' . $out . '</li>'; } return $this->renderText($out); }
if ($route_list_linked) { $url = $base_url . $param1 . '&' . $param2; } else { $url = $base_url . $param2 . '&' . $param1; } echo ' ' . link_to($link_text, $url, array('title' => __($title), 'class' => 'hide', 'rel' => 'nofollow')); } // display tools for manipulating associations if user is moderator and displayed doc // is directly linked to current doc if ($show_link_to_delete && isset($doc['directly_linked'])) { $tips = isset($doc['ghost_id']) && isset($ghost_module) ? 'Delete the association with this ' . $module : null; echo c2c_link_to_delete_element($type, $revert_ids ? $id : $doc_id, $revert_ids ? $doc_id : $id, false, (int) $strict, null, 'indicator', $tips); if (isset($doc['ghost_id']) && isset($ghost_module)) { $ghost_id = $doc['ghost_id']; $tips = 'Delete the association with this ' . $ghost_module; echo c2c_link_to_delete_element($ghost_type, $revert_ghost_ids ? $id : $ghost_id, $revert_ghost_ids ? $ghost_id : $id, false, (int) $strict, null, 'indicator', $tips); } // button for changing a relation order if (in_array($type, array('ss', 'tt', 'pp'))) { list($mi, $li) = $doc['parent_relation'][$id] == 'parent' ? array($id, $doc_id) : array($doc_id, $id); echo link_to(image_tag(sfConfig::get('app_static_url') . '/static/images/picto/move.gif'), "@default?module=documents&action=invertAssociation&type={$type}&main_id={$mi}&linked_id={$li}"); } } echo $is_inline ? '</span>' : '</div>'; } if ($is_inline) { if ($has_merge_inline) { echo ', ' . $sf_data->getRaw('merge_inline'); } echo '</div>'; }
</p> <?php } else { $doc_id = $document->get('id'); $strict = (int) $strict; // cast so that false is 0 and true is 1. ?> <ul class="children_docs"> <?php foreach ($associated_sites as $site) { $site_id = $site->get('id'); $idstring = $type . '_' . $site_id; ?> <li class="child_site" id="<?php echo $idstring; ?> "> <?php echo link_to($site->get('name'), '@document_by_id?module=sites&id=' . $site_id) . ' - ' . field_data_from_list_if_set($site, 'site_types', 'app_sites_site_types', array('multiple' => true, 'raw' => true)); if ($is_moderator && !$mobile_version) { $idstring = $type . '_' . $site_id; echo c2c_link_to_delete_element($type, $doc_id, $site_id, true, $strict); } ?> </li> <?php } ?> </ul> <?php }
$id_list_associated_docs = "list_associated_docs"; if (!count($associated_documents)) { echo '<p class="default_text" id="' . $id_no_associated_docs . '">' . __("No document uses this picture.") . '</p>'; } if (count($associated_documents) > 0) { echo '<ul id="' . $id_list_associated_docs . '">'; foreach ($associated_documents as $doc) { $doc_id = $doc['id']; $module = $doc['module']; $type = c2cTools::Module2Letter($module) . 'i'; $idstring = $type . '_' . $doc_id; echo '<li id="', $idstring, '">'; echo picto_tag('picto_' . $module, __($module)); echo ' ' . link_to($doc['name'], "@document_by_id_lang_slug?module={$module}&id=" . $doc_id . '&lang=' . $doc['culture'] . '&slug=' . make_slug($doc['name'])); if ($show_link_to_delete) { echo c2c_link_to_delete_element($type, $doc_id, $id, false, 1); } echo '</li>'; } echo '</ul>'; } elseif ($show_link_tool) { echo '<ul id="' . $id_list_associated_docs . '"><li style="display:none"></li></ul>'; } if ($show_link_tool) { ?> <div id="association_tool" class="plus"> <p><?php echo __('You can associate this picture with any existing document using the following tool:'); ?> </p> <?php
?> <ul class="children_docs"> <?php foreach ($associated_books as $book) { $book_id = $book->get('id'); $idstring = $type . '_' . $book_id; $class = 'child_book'; if (!$extra_book && isset($book['parent_id'])) { $class .= ' separator'; $extra_book = true; } echo '<li class="' . $class . '" id="' . $idstring . '">'; echo link_to($book->get('name'), '@document_by_id?module=books&id=' . $book_id); if (isset($book['author']) && trim($book['author']) != '') { echo ' - ' . $book['author']; } if (isset($book['publication_date']) && trim($book['publication_date']) != '') { echo ' - ' . $book['publication_date']; } if (!isset($book['parent_id']) && $is_moderator && !$mobile_version) { $idstring = $type . '_' . $book_id; echo c2c_link_to_delete_element($type, $book_id, $doc_id, false, $strict); } ?> </li> <?php } ?> </ul> <?php } }
} $route_link = '@document_by_id_lang_slug?module=routes&id=' . $route_id . '&lang=' . $route->get('culture') . '&slug=' . make_slug($route->get('full_name')); $options = array(); if (!empty($external_links)) { $options['target'] = '_blank'; } if ($list_format) { echo link_to($route->get('name'), $route_link, $options) . '<div class="short_data">' . summarize_route($route, true, false, $avalaible_activities, true) . $georef; if ($show_link_to_delete && isset($route['directly_linked'])) { echo c2c_link_to_delete_element($type, $doc_id, $route_id, true, $strict); } echo '</div>'; } else { echo '<td>' . link_to($route->get('name'), $route_link, $options) . '</td>' . summarize_route($route, true, true, $avalaible_activities, false) . '<td>' . $georef . '</td>'; if ($show_link_to_delete && isset($route['directly_linked'])) { echo '<td>' . c2c_link_to_delete_element($type, $doc_id, $route_id, true, $strict) . '</td>'; } } echo '</' . $line_tag . '>'; } } if ($list_format) { echo '</ul>'; } else { echo '</tbody></table>'; } if (!$activity_section) { if (!empty($routes_list_link)) { echo '<p class="list_link">' . picto_tag('picto_routes') . ' ' . $routes_list_link . '</p>'; } break;