/[drupal]/contributions/modules/carto/carto.module
ViewVC logotype

Diff of /contributions/modules/carto/carto.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.17, Fri Sep 29 14:34:22 2006 UTC revision 1.18, Thu Oct 5 20:13:05 2006 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: carto.module,v 1.16 2006/09/29 08:19:42 openwereld Exp $  // $Id: carto.module,v 1.17 2006/09/29 14:34:22 openwereld Exp $
3    
4  define( 'DEFAULT_WMS_SEARCH_FIELDS', 'name,title,abstract' );  define( 'DEFAULT_WMS_SEARCH_FIELDS', 'name,title,abstract' );
5    define( 'DEFAULT_CARTO_WMS_TEASER_MAP', 1 );
6  /**  /**
7   * Implementation of hook_help().   * Implementation of hook_help().
8   *   *
# Line 58  function carto_help( $section ) Line 58  function carto_help( $section )
58          // no help for the configuration of the legend block          // no help for the configuration of the legend block
59          break;          break;
60    
61      case 'node/add#carto-wms':      case 'node/add#cartowms':
62  //print 'carto_help:' . $section . '<br />';  //print 'carto_help:' . $section . '<br />';
63          $output = t('Add a Opengis web mapping service.');          $output = t('Add a Opengis web mapping service.');
64          break;          break;
# Line 154  function carto_menu( $may_cache ) Line 154  function carto_menu( $may_cache )
154    
155      if( $may_cache )      if( $may_cache )
156      {      {
157          $items[] = array( 'path' => 'node/add/carto-wms'          $items[] = array( 'path' => 'node/add/cartowms'
158                  , 'title' => t('wms node')                  , 'title' => t('wms node')
159                  , 'access' => user_access('create wms nodes')                  , 'access' => user_access('create wms nodes')
160                  );                  );
# Line 175  function carto_menu( $may_cache ) Line 175  function carto_menu( $may_cache )
175                  );                  );
176          $items[] = array( 'path' => 'carto/maps/' . $user->uid          $items[] = array( 'path' => 'carto/maps/' . $user->uid
177                  , 'title' => t('my maps')                  , 'title' => t('my maps')
178                  , 'access' => user_access('access content')                  , 'access' => $user->uid > 0 && user_access('access content')
179                  , 'type' => MENU_NORMAL_ITEM                  , 'type' => MENU_NORMAL_ITEM
180                  );                  );
181    
# Line 186  function carto_menu( $may_cache ) Line 186  function carto_menu( $may_cache )
186                  , 'access' => user_access('access wms nodes')                  , 'access' => user_access('access wms nodes')
187                  , 'type' => MENU_NORMAL_ITEM                  , 'type' => MENU_NORMAL_ITEM
188                  );                  );
189          $items[] = array( 'path' => 'carto/wms/' . $user->uid          $items[] = array( 'path' => 'carto/wms/user/' . $user->uid
190                  , 'title' => t('my wms')                  , 'title' => t('my wms')
191                  , 'access' => user_access('create wms nodes')                  , 'access' => $user->uid > 0 && user_access('access wms nodes')
192                  , 'type' => MENU_NORMAL_ITEM                  , 'type' => MENU_NORMAL_ITEM
193                  );                  );
194    
# Line 226  function carto_menu( $may_cache ) Line 226  function carto_menu( $may_cache )
226                  , 'access' => user_access('access content')                  , 'access' => user_access('access content')
227                  );                  );
228      }      }
229        else
230        {
231            if( arg(0) == 'node' && is_numeric(arg(1)) && user_access('select wms layers'))
232            {
233                // Only add the 'select layers'-tab for cartowms pages:
234                $result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d AND n.type = 'cartowms'"), arg(1));
235                if (db_num_rows($result) > 0)
236                {
237                    $items[] = array( 'path' => 'node/' . arg(1) . '/layers'
238                        , 'title' => t('select layers')
239                        , 'callback' => 'drupal_get_form', 'callback arguments' => array('carto_wms_select_layers', intval(arg(1)))
240                        , 'access' => user_access('select wms layers')
241                        , 'type' => MENU_LOCAL_TASK
242                        );
243                }
244            }
245            //drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'core');
246        }
247      return $items;      return $items;
248  }  }
249    
# Line 238  function carto_menu( $may_cache ) Line 256  function carto_menu( $may_cache )
256   */   */
257  function carto_admin_settings( )  function carto_admin_settings( )
258  {  {
     // only for administrators  
     if( ! user_access( "administer carto" ) )  
     {  
         return message_access();  
     }  
   
     $content = '';  
   
259      $sql = "select count(*) as count from {carto_filter_blocks}";      $sql = "select count(*) as count from {carto_filter_blocks}";
260      $result = db_query( $sql );      $result = db_query( $sql );
261      $item = db_fetch_object( $result );      $item = db_fetch_object( $result );
# Line 265  function carto_admin_settings( ) Line 275  function carto_admin_settings( )
275          , '#description' => t("Check this box to empty the '%table' table"          , '#description' => t("Check this box to empty the '%table' table"
276              , array('%table' => 'carto_filter_blocks'))              , array('%table' => 'carto_filter_blocks'))
277          );          );
278        $form['carto']['carto_wms_teaser_map'] = array(
279            '#type' => 'checkbox'
280            , '#title' => t('Show map in teaser of web mapping service')
281            , '#default_value' => variable_get('carto_wms_teaser_map',DEFAULT_CARTO_WMS_TEASER_MAP) != 0
282            , '#description' => t('Check to show map in teaser of web mapping service')
283            );
284    
285      // mappingwidgets group      // mappingwidgets group
286      $form['mappingwidgets'] = array(      $form['mappingwidgets'] = array(
# Line 383  function carto_admin_settings_validate( Line 399  function carto_admin_settings_validate(
399      {      {
400          form_set_error( 'smarty][carto_smarty_dir', t('Wrong installation folder. The folder must end with a / and must contain Smarty.class.php.') );          form_set_error( 'smarty][carto_smarty_dir', t('Wrong installation folder. The folder must end with a / and must contain Smarty.class.php.') );
401      }      }
402  //    drupal_set_message( t("carto_settings_form_validate $form_id: " . var_export($form,true)) );      //drupal_set_message( t("carto_settings_form_validate $form_id: " . var_export($form,true)) );
403  }  }
404    
405  /**  /**
# Line 392  function carto_admin_settings_validate( Line 408  function carto_admin_settings_validate(
408   */   */
409  function carto_admin_settings_submit( $form_id, $values )  function carto_admin_settings_submit( $form_id, $values )
410  {  {
411        if( $values['op'] == t('Reset to defaults') )
412        {
413            variable_del( 'carto_wms_teaser_map' );
414        }
415        else if( $values['op'] == t('Save configuration') )
416        {
417            variable_set( 'carto_wms_teaser_map', $values['carto']['carto_wms_teaser_map'] );
418        }
419    
420      if( $values['carto']['carto_empty_cache'] == 1 )      if( $values['carto']['carto_empty_cache'] == 1 )
421      {      {
422          // empty carto_filter_blocks table          // empty carto_filter_blocks table
# Line 432  function carto_admin_settings_submit( $f Line 457  function carto_admin_settings_submit( $f
457  }  }
458    
459  /**  /**
  * Theme function for 'carto_settings_form'.  
  *  
 function theme_carto_settings_form( $form )  
 {  
     $output .= '<pre>' . var_export($form,true) . '</pre>';  
 //    $output .= theme( 'table', $form );  
   
     return $output;  
 }  
 /* */  
   
 /**  
  * Implementation of hook_all().???  
  *  
 function carto_all( )  
 {  
     $page_content = "";  
   
     // pagina inhoud geven  
   
     if( $page_content == "" )  
     {  
         print theme( "page", "Carto: er is geen inhoud te melden" );  
         return;  
     }  
     print theme( "page", $page_content );  
 }  
 */  
   
 /**  
  * Implementation of hook_link().  
  *  
 function carto_link( $type, $node = 0 )  
 {  
     if( $type == "system" )  
     {  
         menu( "carto", t("Carto"), carto_all, 1, 0 );  
     }  
 }  
 */  
   
 /**  
460   *   *
461   */   */
462  function carto_all( )  function carto_all( )
# Line 679  function carto_block( $op = 'list', $del Line 662  function carto_block( $op = 'list', $del
662              break;              break;
663          }          }
664          return $form;          return $form;
   
         // drupal < 4.7  
         $output = '';  
         switch( $delta )  
         {  
         case 0:  
             $output .= form_textfield( t('Number of maps'), 'carto_recent_maps', variable_get('carto_recent_maps',10), 5, 5, t('Maximum number of recent maps to show.') );  
             break;  
         case 1:  
             // block specific settings  
             $output .= form_textfield( t('Width'), 'carto_overview_width', variable_get('carto_overview_width',160), 5, 5, t('Width of the overview block.') );  
             $output .= form_textfield( t('Height'), 'carto_overview_height', variable_get('carto_overview_height',80), 5, 5, t('Height of the overview block.') );  
             break;  
         case 2:  
             // block specific settings  
             $output .= form_textfield( t('Width'), 'carto_legend_width', variable_get('carto_legend_width',160), 5, 5, t('Width of the legend block.') );  
             $output .= form_textfield( t('Height'), 'carto_legend_height', variable_get('carto_legend_height',240), 5, 5, t('Height of the legend block.') );  
             break;  
         }  
         return $output;  
665      }      }
666      else if( $op == 'save' )      else if( $op == 'save' )
667      {      {
# Line 1198  function carto_nodeapi( &$node, $op, $te Line 1161  function carto_nodeapi( &$node, $op, $te
1161  function carto_node_info()  function carto_node_info()
1162  {  {
1163      return array(      return array(
1164          'carto-wms' => array( 'name' => t('web mapping service')          'cartowms' => array( 'name' => t('web mapping service')
1165                              , 'module' => 'carto_wms'                              , 'module' => 'carto_wms'
1166                              , 'description' => t('todo: description of carto-wms node type')                              , 'description' => t('todo: description of carto-wms node type')
1167                                //, 'has_body' => TRUE
1168                                //, 'body_label' => t('Capabilities')
1169                              )                              )
1170      );      );
1171  }  }
1172    
1173  function carto_wms_form( &$node )  function carto_wms_form( &$node )
1174  {  {
1175  //    print 'carto_wms_form: ' . var_export(array("OP" => $_POST['op'], "NODE" => $node,"EDIT" => $_POST['edit']),true) . '<hr>';      //print 'carto_wms_form: ' . var_export(array('POST'=>$_POST,'NODE'=>$node),true) . '<hr>';
1176        $type = node_get_types('type', $node);
     if( isset($_POST['op']) )// == t('Preview') )  
     {  
         if( $_POST['edit']['getcapabilities'] && $_POST['edit']['capabilities'] == '' )  
         {  
             $url = $_POST['edit']['service'] . "&service=wms&request=GetCapabilities";  
             $response = drupal_http_request( $url );  
             if( $response->code == 200 )  
             {  
                 // Set capabilities value in $_POST  
                 // Note: form value is determined by 1) $_POST (if set) or else  
                 // by 2) #default_value. An alternative is to use #value?  
                 $_POST['edit']['capabilities'] = $response->data;  
             }  
         }  
     }  
1177    
1178      $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title );      $form['title'] = array( '#type' => 'textfield'
1179            , '#title' => check_plain($type->title_label)//t('Title')
1180            , '#required' => TRUE
1181            , '#default_value' => $node->title
1182            );
1183      $form['service'] = array( '#type' => 'textfield', '#title' => t('Web mapping service')      $form['service'] = array( '#type' => 'textfield', '#title' => t('Web mapping service')
1184          , '#size' => 100          , '#size' => 100
1185          , '#maxlength' => 1000          , '#maxlength' => 1000
1186          , '#required' => TRUE, '#default_value' => $node->service );          , '#required' => TRUE, '#default_value' => $node->service );
1187      $form['getcapabilities'] = array( '#type' => 'checkbox', '#title' => t('Get capabilities'), '#required' => FALSE );      $form['getcapabilities'] = array( '#type' => 'checkbox', '#title' => t('Get capabilities'), '#required' => FALSE );
1188      $form['capabilities'] = array( '#type' => 'textarea', '#title' => t('Capabilities'), '#required' => FALSE, '#rows' => 20, '#default_value' => $node->capabilities );      $form['capabilities'] = array( '#type' => 'textarea'
1189            , '#title' => t('Capabilities')
1190            , '#required' => FALSE, '#rows' => 20
1191            , '#default_value' => $node->capabilities
1192            );
1193    
1194      $form['format'] = filter_form( $node->format );      $form['format'] = filter_form( $node->format );
1195      return $form;      return $form;
# Line 1239  function carto_wms_form( &$node ) Line 1197  function carto_wms_form( &$node )
1197    
1198  function carto_wms_validate( &$node )  function carto_wms_validate( &$node )
1199  {  {
1200  //    print 'carto_wms_validate: ' . var_export(array("OP" => $_POST['op'], "NODE" => $node,"EDIT" => $_POST['edit']),true) . '<hr>';      //print 'carto_wms_validate: ' . var_export(array("POST" => $_POST, "NODE" => $node),true) . '<hr>';
1201    
1202      if( $node->capabilities == '' )//&& $_POST['edit']['capabilities'] == '' )      if( $node->capabilities == '' && $node->getcapabilities == 1 )//&& $_POST['edit']['capabilities'] == '' )
1203      {      {
1204          form_set_error('capabilities', t('The capabilities must be present!'));          $url = $node->service . "&service=wms&request=GetCapabilities";
1205            $response = drupal_http_request( $url );
1206            //drupal_set_message( var_export($response,true) );
1207            if( $response->code == 200 )
1208            {
1209                // Set capabilities value in $_POST
1210                // Note: form value is determined by 1) $_POST (if set) or else
1211                // by 2) #default_value. An alternative is to use #value?
1212                $node->capabilities = $response->data;
1213                drupal_set_message( 'Capabilities were requested in carto_wms_validate' );
1214            }
1215            else
1216            {
1217                form_set_error('capabilities', t('The capabilities must be present!'));
1218            }
1219      }      }
1220    
1221  //    form_set_error('capabilities','carto_wms_validate functie:' . var_export($node,true) );  //    form_set_error('capabilities','carto_wms_validate functie:' . var_export($node,true) );
# Line 1251  function carto_wms_validate( &$node ) Line 1223  function carto_wms_validate( &$node )
1223    
1224  function carto_wms_submit( &$node )  function carto_wms_submit( &$node )
1225  {  {
1226  //    print 'carto_wms_submit:' . var_export(array("NODE" => $node,"EDIT" => $_POST['edit']),true) . '<hr>';      //print 'carto_wms_submit:' . var_export(array("NODE" => $node,"EDIT" => $_POST['edit']),true) . '<hr>';
1227  }  }
1228    
1229  function carto_wms_insert( $node )  function carto_wms_insert( $node )
1230  {  {
1231  //    print 'carto_wms_insert:' . var_export(array("NODE" => $node,"EDIT" => $_POST['edit']),true) . '<hr>';      print 'carto_wms_insert:' . var_export(array("NODE" => $node,"EDIT" => $_POST['edit']),true) . '<hr>';
1232      $caps = & new CapabilitiesParser( );      $caps = & new CapabilitiesParser( );
1233    
1234      // @todo: do this (get capabilities) in validate function      // @todo: do this (get capabilities) in validate function
1235      if( $node->getcapabilities && $node->capabilities == '')      if( $node->getcapabilities && $node->capabilities == '')
1236      {      {
1237  //        carto_wms_validate( $node );  //        carto_wms_validate( $node );
1238            $url = $node->service . "&service=wms&request=GetCapabilities";
1239            $response = drupal_http_request( $url );
1240            //drupal_set_message( var_export($response,true) );
1241            if( $response->code == 200 )
1242            {
1243                // Set capabilities value in $_POST
1244                // Note: form value is determined by 1) $_POST (if set) or else
1245                // by 2) #default_value. An alternative is to use #value?
1246                $node->capabilities = $response->data;
1247                drupal_set_message( 'Capabilities were requested in carto_wms_insert' );
1248            }
1249      }      }
1250    
1251      $caps->parse( $node->capabilities, "insert_capabilities", & $node );      $caps->parse( $node->capabilities, "insert_capabilities", & $node );
# Line 1272  function carto_wms_insert( $node ) Line 1255  function carto_wms_insert( $node )
1255    
1256  function insert_capabilities( $layer, $node )  function insert_capabilities( $layer, $node )
1257  {  {
1258  //    print 'insert_capabilities ' . $layer['layer_id'] . '<br>';  //    print 'insert_capabilities ' . var_export($layer,true) . '<br>';
1259      if( $layer['layer_id'] == 1 )      if( $layer['layer_id'] == 1 )
1260      {      {
1261          db_query( "INSERT INTO {carto_wms_node} ( nid, service, capabilities, bbox )"          db_query( "INSERT INTO {carto_wms_node} ( nid, service, capabilities, bbox )"
# Line 1361  function update_capabilities( $layer, $n Line 1344  function update_capabilities( $layer, $n
1344      insert_capabilities( $layer, $node );      insert_capabilities( $layer, $node );
1345  }  }
1346    
1347    function carto_wms_nodeapi( &$node, $op, $teaser, $page)
1348    {
1349        drupal_set_message( 'carto_wms_nodeapi: ' . $op );
1350        switch ($op)
1351        {
1352            case 'delete revision':
1353                // todo: use versions vid!!
1354                // Notice that we're matching a single revision based on the node's vid.
1355                //db_query('DELETE FROM {carto_wms_node} WHERE vid = %d', $node->vid);
1356                break;
1357        }
1358    }
1359    
1360  function carto_wms_delete( &$node )  function carto_wms_delete( &$node )
1361  {  {
1362  //    print 'carto_wms_delete' . '<br>';  //    print 'carto_wms_delete' . '<br>';
# Line 1377  function carto_wms_load( $node ) Line 1373  function carto_wms_load( $node )
1373          $additions->layers = 'Countries';          $additions->layers = 'Countries';
1374      if( ! $additions->bbox )      if( ! $additions->bbox )
1375          $additions->bbox = '-180,-90,180,90';          $additions->bbox = '-180,-90,180,90';
1376  //    print "carto_wms_load({$node->nid}): " . /*var_export($additions,true) .*/ '<br>';      //print "carto_wms_load({$node->nid}): " . var_export($additions,true) . '<br>';
1377      return $additions;      return $additions;
1378  }  }
1379    
# Line 1395  function carto_wms_view( &$node, $teaser Line 1391  function carto_wms_view( &$node, $teaser
1391      }      }
1392      // prepare the node content      // prepare the node content
1393      $node = carto_wms_content( $node, $teaser );      $node = carto_wms_content( $node, $teaser );
1394        return $node;
1395  }  }
1396    
1397  /**  /**
# Line 1439  function carto_wms_content($node, $tease Line 1436  function carto_wms_content($node, $tease
1436      $content .= '<p>Capabilities: <a href="' . $node->service . '&service=wms&request=GetCapabilities">click here</a>' . "</p>\n";      $content .= '<p>Capabilities: <a href="' . $node->service . '&service=wms&request=GetCapabilities">click here</a>' . "</p>\n";
1437      $content .= '<p>Layers: ' . $node->layers . "</p>\n";      $content .= '<p>Layers: ' . $node->layers . "</p>\n";
1438    
1439      $node->teaser = $content;      if( variable_get('carto_wms_teaser_map',1) )//! $teaser )
   
     if( ! $teaser )  
1440      {      {
1441          // @todo: only if access to carto filter?          // @todo: only if access to carto filter?
1442    
# Line 1496  function carto_wms_content($node, $tease Line 1491  function carto_wms_content($node, $tease
1491  {mappingwidget type=\"ZoomLast\" target=\"previous\"}  {mappingwidget type=\"ZoomLast\" target=\"previous\"}
1492  {/carto-filter}";  {/carto-filter}";
1493    
1494          $content .= '<pre style="width: 90%; overflow: auto;">' . $widget_text . '</pre>';          //$content .= '<pre style="width: 90%; overflow: auto;">' . $widget_text . '</pre>';
   
         if( user_access('create wms nodes') || user_access( 'select wms layers' ) )  
         {  
             // add checkboxes for layers  
             $results = db_query( "SELECT * FROM {carto_wms_layer} WHERE nid = %d", $node->nid );  
             $headers = array('nid','lid','name','title','abstract','minx','miny','maxx','maxy','queryable','opaque','cascaded');  
   
             //$content .= "<form action=\"javascript:alert('Hoi');\">";  
             $content .= "<form action=\"\" method=\"post\">";  
   
             $i = 0;  
             $rows = array();  
             while( ($row = db_fetch_array( $results )) != NULL )  
             {  
                 //$content .= var_export($row,true);  
                 // layer:  nid, lid, name, title, abstract, minx..maxy, queryable, opaque, cascaded  
     //            $content .= form_checkboxes( t('Layers'), 'layers', NULL, array( '0' => '1st layer' ) );  
                 if( $row['name'] )  
                 {  
                     $row['nid'] = '<input type="checkbox" name="edit[layer][' . $i . ']" id="edit-layer-'. $i  
                         . '" value="' . $row['name'] . '" '  
                         . ( in_array($row['name'],$layers) ? 'checked' : '' ) .' />';  
                 }  
                 else  
                     $row['nid'] = '';  
   
                 $rows[] = $row;  
                 $i++;  
             }  
             $content .= theme_table( $headers, $rows, array( 'border' => '1', 'width' => '100%' ) );  
             $content .= "<input type=\"submit\" name=\"Tekenen\" /></form>";  
         }  
1495    
1496  //        $content .= var_export($node,true);  //        $content .= var_export($node,true);
1497    
1498          $node->body = $content;          $node->body = $content;
1499  //        $node->format = 4; // @todo: lookup carto-filter format  //        $node->format = 4; // @todo: lookup carto-filter format
1500      }      }
1501        $node->teaser = $content;
1502    
1503      return node_prepare( $node, $teaser );      return node_prepare( $node, $teaser );
1504  }  }
1505    
# Line 1542  if( file_exists(variable_get('carto_mapp Line 1507  if( file_exists(variable_get('carto_mapp
1507  {  {
1508  include_once( variable_get('carto_mappingwidgets_dir',MAPPINGWIDGETS_DIR) . 'wms-parser.php' );  include_once( variable_get('carto_mappingwidgets_dir',MAPPINGWIDGETS_DIR) . 'wms-parser.php' );
1509    
 /*  
 function carto_validate( &$node )  
 {  
     print 'carto_validate' . '<br>';  
   
     if( $node->getcapabilities )  
     {  
         $url = $node->service . "&service=wms&request=getcapabilities";  
 //print 'capabilities: ' . $url . '<br>';  
         $response = drupal_http_request( $url );  
         if( $response->code == 200 )  
         {  
             $node->capabilities = $response->data;  
         }  
         else  
             form_set_error('capabilities', t("Getcapabilities request failed. Error %code: %error",array('%code'=>$response->code,'%error'=>$response->error)) );  
     }  
   
     if( $node->capabilities == '' )  
     {  
         form_set_error('capabilities', t('The capabilities must be present!'));  
     }  
     else  
     {  
         // check validity of xml  
 //        $caps = & new CapabilitiesParser( );  
 //        $caps->parse( $node->capabilities, "cbLayer" );  
 //        $caps->free_parser( );  
   
 //        $node->caps = & $caps;  
   
 //        form_set_error( '', 'caps: ' . var_export($caps,true) );  
   
 /*  
         $str = '';  
         $doc = domxml_open_mem( $node->capabilities );  
         $layers = $doc->get_elements_by_tagname( "Layer" );  
         foreach( $layers as $element )  
         {  
 //            $str .= var_export($element,true);  
         }  
   
         $root = $doc->document_element();  
 //        $str .= var_export( $root, true );  
   
         // get wms version number  
         $node->version = $root->get_attribute('version');  
   
         //$result = $ctx->xpath_eval("/WMT_MS_Capabilities[version]");  
   
         //$result = $ctx->xpath_eval("/cars/car[normalize-space(maxspeed/text())>300 and normalize-space(type/text())='F1']");  
         $xpath = $doc->xpath_init();  
         $ctx = $doc->xpath_new_context();  
   
         // get service info  
         $result = $ctx->xpath_eval("/{$root->tagname}/Service");  
         form_set_error( '', var_export($result->nodeset,true) );  
         if( $result->nodeset[0] ){  
         foreach( $result->nodeset[0]->child_nodes() as $n )  
         {  
             switch( $n->tagname )  
             {  
                 case 'Name':  
                 case 'Title':  
                 case 'Abstract':  
                     form_set_error( '', $n->tagname . '=' . $n->get_content() );  
                     break;  
                 case 'OnlineResource':  
                     form_set_error( '', $n->tagname . '=' . var_export($n,true) );  
                     break;  
             }  
         }  
         }  
 */  
 /*  
     }  
 }  
   
 function carto_insert( $node )  
 {  
     print 'carto_insert' . '<br>';  
   
     switch( $node->type )  
     {  
         case 'carto-wms':  
 //print 'insert wms: ' . var_export($node->caps,true) . '<br>';  
             $caps = & new CapabilitiesParser( );  
             $caps->parse( $node->capabilities, "insert_capabilities", & $node );  
             $caps->free_parser( );  
   
             break;  
         case 'carto-wfs':  
             break;  
     }  
 }  
   
 function cbLayer( $layer, $node )  
 {  
     insert_capabilities( $layer, $node );  
     print 'cblayer ' . $node->nid . '/' . var_export($layer,true) . '<br>';  
 }  
   
 function carto_update( $node )  
 {  
     print 'carto_update' . '<br>';  
   
     switch( $node->type )  
     {  
         case 'carto-wms':  
             $caps = & new CapabilitiesParser( );  
 //            $caps->parse( $node->capabilities, "cbLayer", & $node );  
             $caps->parse( $node->capabilities, "update_capabilities", & $node );  
             $caps->free_parser( );  
             break;  
         case 'carto-wfs':  
             break;  
     }  
 }  
   
 function carto_delete( &$node )  
 {  
     print 'carto_delete' . '<br>';  
   
     switch( $node->type )  
     {  
         case 'carto-wms':  
             db_query( "DELETE FROM {carto_wms_node} WHERE nid = %d", $node->nid );  
             db_query( "DELETE FROM {carto_wms_layer} WHERE nid = %d", $node->nid );  
             db_query( "DELETE FROM {carto_wms_layer_properties} WHERE nid = %d", $node->nid );  
             break;  
         case 'carto-wfs':  
             break;  
     }  
 }  
   
 /**  
  * Implementation of hook_load.  
  *  
 function carto_load($node)  
 {  
     $additions = db_fetch_object(db_query('SELECT service, capabilities, layers, bbox FROM {carto_wms_node} WHERE nid = %d', $node->nid));  
     $additions->srs = 'epsg:4326';  
     if( ! $additions->layers )  
         $additions->layers = 'Countries';  
     if( ! $additions->bbox )  
         $additions->bbox = '-180,-90,180,90';  
     return $additions;  
 }  
   
 function carto_view( &$node, $teaser = FALSE, $page = FALSE )  
 {  
     if( $page )  
     {  
         // Breadcrumb navigation  
         $breadcrumb = array();  
         $breadcrumb[] = array( 'path' => 'carto', 'title' => t('cartographies') );  
         $breadcrumb[] = array( 'path' => 'carto/'. $node->uid, 'title' => t("%name's cartography", array('%name' => $node->name)) );  
         $breadcrumb[] = array( 'path' => 'node/'. $node->nid );  
         menu_set_location( $breadcrumb );  
     }  
     switch( $node->type )  
     {  
         case 'carto-wms':  
             // prepare the node content  
             $node = carto_content( $node, $teaser );  
             break;  
         case 'carto-wfs':  
             break;  
     }  
 }  
   
 /**  
  * Implementation of hook_content().  
  *  
 function carto_content($node, $teaser = FALSE)  
 {  
     $content = '';  
     $content .= '<p>Web service: ' . $node->service . "</p>\n";  
     $content .= '<p>Capabilities: <a href="' . $node->service . '&service=wms&request=getcapabilities">click here</a>' . "</p>\n";  
     $content .= '<p>Layers: ' . $node->layers . "</p>\n";  
     $node->teaser = $content;  
   
     if( ! $teaser )  
     {  
         // @todo: derive width/height from $node->bbox  
         $width = 540;  
   
         $extent = explode( ',',$node->bbox );  
         if( count($extent) == 4 )  
             $height = intval($width * floatval($extent[3] - $extent[1])/floatval($extent[2] - $extent[0]));  
         else  
             $height = 270;  
   
         if( $height > 540 )  
         {  
             $height = 540;  
             $width = intval($height * floatval($extent[2] - $extent[0])/floatval($extent[3] - $extent[1]));  
         }  
   
   
         $imageformat = "image/png";  
   
         $content .= "  
 {carto-filter}  
   {mappingwidget type=\"SimpleMap\" service=\"{$node->service}&version=1.1.1\"  
     width=\"$width\" height=\"$height\"  
     layers=\"{$node->layers}\"  
     extent=\"{$node->bbox}\" srs=\"{$node->srs}\"  
     format=\"$imageformat\"  
     maxextent=\"{$node->bbox}\"  
     overview=\"images/world.png\"  
   }  
 {/carto-filter}  
 {carto-filter}  
 {mappingwidget type=\"ZoomIn\" group=\"navigation\" target=\"previous\"}  
 {mappingwidget type=\"ZoomOut\" group=\"navigation\" target=\"previous\"}  
 {mappingwidget type=\"Move\" group=\"navigation\" target=\"previous\"}  
 {mappingwidget type=\"Query\" group=\"navigation\" target=\"previous\"}  
 {mappingwidget type=\"Ruler\" group=\"navigation\" mode=\"close\" target=\"previous\"}  
 {mappingwidget type=\"ZoomFull\" target=\"previous\"}  
 {mappingwidget type=\"ZoomFirst\" target=\"previous\"}  
 {mappingwidget type=\"ZoomPrevious\" target=\"previous\"}  
 {mappingwidget type=\"ZoomNext\" target=\"previous\"}  
 {mappingwidget type=\"ZoomLast\" target=\"previous\"}  
 {/carto-filter}";  
   
         // add checkboxes for layers  
         $results = db_query( "SELECT * FROM {carto_wms_layer} WHERE nid = %d", $node->nid );  
         $headers = array('nid','lid','name','title','abstract','minx','miny','maxx','maxy','queryable','opaque','cascaded');  
         $rows = array();  
         while( ($row = db_fetch_object( $results )) != NULL )  
         {  
             //$content .= var_export($row,true);  
             // layer:  nid, lid, name, title, abstract, minx..maxy, queryable, opaque, cascaded  
 //            $content .= form_checkboxes( t('Layers'), 'layers', NULL, array( '0' => '1st layer' ) );  
             $rows[] = $row;  
         }  
         $content .= theme_table( $headers, $rows, array( 'border' => '1', 'width' => '100%' ) );  
   
 //        $content .= var_export($node,true);  
   
         $node->body = $content;  
         $node->format = 4; // @todo: lookup carto-filter format  
     }  
     return node_prepare( $node, $teaser );  
 }  
 */  
   
1510  function carto_search( $op = 'search', $keys = NULL )  function carto_search( $op = 'search', $keys = NULL )
1511  {  {
1512  //            print 'carto search: ' . $op . "<br>\n";  //            print 'carto search: ' . $op . "<br>\n";
# Line 1838  function carto_search( $op = 'search', $ Line 1555  function carto_search( $op = 'search', $
1555          case 'search': // in search/carto{/search_phrase}          case 'search': // in search/carto{/search_phrase}
1556              break;              break;
1557    
1558            case 'reset':
1559                break;
1560    
1561          default:          default:
1562              print 'carto search: ' . $op . "<br>\n";              print 'carto search: ' . $op . "<br>\n";
1563              break;              break;
# Line 1857  function carto_search_item($item) Line 1577  function carto_search_item($item)
1577      return $output;      return $output;
1578  }  }
1579    
1580  function carto_wms_all( $uid = 0 )  function carto_wms_all( $type = '', $id = 0 )
1581  {  {
1582      if( $uid )      if( $type == 'user' && $id )
1583        {
1584            carto_wms_user( $id );
1585        }
1586        else if( $type == 'node' && $id )
1587      {      {
1588          carto_wms_user($uid);          carto_wms_service( $id );
1589      }      }
1590      else      else
1591      {      {
# Line 1869  function carto_wms_all( $uid = 0 ) Line 1593  function carto_wms_all( $uid = 0 )
1593      }      }
1594  }  }
1595    
1596    function carto_wms_service( $nid )
1597    {
1598        $request = strtolower( $_GET['request'] );
1599        switch( $request )
1600        {
1601            case 'getcapabilities':
1602                drupal_set_header( "Content-Type: text/xml" );
1603                $node = node_load( $nid );
1604                echo $node->capabilities;
1605                break;
1606    
1607            case 'getmap':
1608                echo 'todo: handle wms service request to wms node';
1609                // todo: pass arguments to wms service
1610                break;
1611    
1612            default:
1613                $output = 'Not a valid request';
1614                echo theme( 'page', $output );
1615        }
1616    }
1617    
1618  function carto_wms_user( $uid )  function carto_wms_user( $uid )
1619  {  {
1620      $account = user_load( array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1) );      $account = user_load( array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1) );
# Line 2031  function carto_simpletest() Line 1777  function carto_simpletest()
1777      return array_keys($tests);      return array_keys($tests);
1778  }  }
1779    
1780    function carto_wms_select_layers( $nid )
1781    {
1782        $form = array();
1783    
1784        // get currently selected layers
1785        $results = db_fetch_array( db_query( "SELECT layers FROM {carto_wms_node} WHERE nid = %d", $nid ) );
1786        $layers = explode(',',$results['layers']);
1787    
1788        // add checkboxes for layers
1789        $results = db_query( "SELECT * FROM {carto_wms_layer} WHERE nid = %d", $nid );
1790        $headers = array('nid','lid','name','title','abstract','minx','miny','maxx','maxy','queryable','opaque','cascaded');
1791    
1792        $i = 0;
1793        $rows = array();
1794        while( ($row = db_fetch_array( $results )) != NULL )
1795        {
1796            if( $row['name'] )
1797            {
1798                $form[ $row['name'] ]['name'] = array( '#type' => 'item'
1799                    , '#title' => $row['name']
1800                    , '#value' => $row['abstract']
1801                    );
1802                $options[ $row['name'] ] = '';
1803                if( in_array($row['name'],$layers) )
1804                    $status[] = $row['name'];
1805            }
1806        }
1807        $form['status'] = array( '#type' => 'checkboxes', '#options' => $options, '#default_value' => $status );
1808        $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
1809        $form['nid'] = array( '#type' => 'hidden', '#value' => $nid );
1810    
1811        return $form;
1812    }
1813    
1814    function theme_carto_wms_select_layers( $form )
1815    {
1816        foreach (element_children($form) as $key)
1817        {
1818            $row = array();
1819            if (is_array($form[$key]['name']))
1820            {
1821                $row[] = array('data' => drupal_render($form['status'][$key]), 'align' => 'center');
1822                $row[] = drupal_render($form[$key]['name']);
1823            }
1824            $rows[] = $row;
1825        }
1826    
1827        $header = array( t('Enabled'), t('Name') );
1828        $output = theme('table', $header, $rows);
1829        $output .= drupal_render($form);
1830        return $output;
1831    }
1832    
1833    function carto_wms_select_layers_validate( $form_id, $form_values )
1834    {
1835        $layers = implode(',',array_diff(array_values($form_values['status']),array(0)));
1836        if( $layers == '' )
1837        {
1838            form_set_error( 'status', t('At least one layer must be selected') );
1839        }
1840    }
1841    
1842    function carto_wms_select_layers_submit( $form_id, $form_values )
1843    {
1844        $layers = implode(',',array_diff(array_values($form_values['status']),array(0)));
1845        $nid = $form_values['nid'];
1846        db_query( "UPDATE {carto_wms_node} SET layers = '%s' WHERE nid = %d", $layers, $nid );
1847    }
1848    
1849  ?>  ?>

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.2