CVS edit link for zwieciu

Hello,

As per the answer I got from WorldFallz (http://drupal.org/node/131074), I'd love to contribute a PGL module to drupal which interfaces our online reservation system, planyo (http://www.planyo.com). The system itself has free and paid versions and is a highly customizable booking management system for reservations of pretty much anything (tennis courts, rental cars, holiday apartments, hostels, boats). The system is available in 8 languages and can be also translated by users to further ones. It also has an API so there are further integration possibilities for future versions of the module.

The module is 100% finished, joomla and DreamWeaver versions have been already added to their respective directories. I believe this module will be very appreciated by developers using Drupal who need a complex reservation system for their commercial customers (which includes invoicing, collaboration between different moderators, online payments, multi-language support etc. -- all this is included in planyo).

Download link and installation instructions for the Drupal module are available at http://www.planyo.com/drupal-reservation-system/

General info and tutorial movies can be found at http://www.planyo.com/

Please let me know if you find some information is missing or incomplete.

Best regards,
Rafael Zwiegincew
planyo.com

Comments

zwieciu’s picture

Component: Miscellaneous » Code
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new53.53 KB
avpaderno’s picture

Component: Code » Miscellaneous

Please change only the status, when you upload new code; other metadata is not though to be changed from the applicant.

avpaderno’s picture

Status: Needs review » Needs work
  1. Files available from third-party sites should not be included in Drupal.org CVS.
  2. In Drupal.org CVS the only accepted files are the ones licensed under GPL license v2+; compatible licenses are not accepted.
  3. The file LICENSE.txt needs to be removed; Drupal.org CVS doesn't allow to commit that file. The file then makes reference to the wrong GPL license version, as Drupal is licensed under GPL License v2+; that is the same license that each file uploaded in CVS repository has.
avpaderno’s picture

Issue tags: +Module review
zwieciu’s picture

StatusFileSize
new22.99 KB

Hi KiamLaLuno,

I have now corrected the problems you mentioned. Attached is the updated version.
Sorry for the status, I didn't know how it works.

Cheers,
Rafael.

avpaderno’s picture

Status: Needs work » Needs review

Remember to change the status, when you upload new code.

dave reid’s picture

Just some quick thoughts:

1. Why is ulap.php and send_http_post() necessary when drupal_http_request is included in core?
2. Functions in utils.js aren't prefixed with the module shortname and might cause conflicts with other defined JS functions (maybe they overwrite, but that would still be unintended behavior). Maybe look into depending on date.module?
3. Don't put a blank index.php in the module.
4. Don't hard-code the version in planyo.info. The drupal.org packaging system will automatically add the important information for you when you create official releases.
5. If you don't have any code in planyo.install, planyo.pages.inc, planyo.admin.inc, don't need to have the files. :)

avpaderno’s picture

Status: Needs review » Needs work

I am changing the status as per previous comment.

zwieciu’s picture

StatusFileSize
new22.56 KB

Thanks for the quick reply.

Attached is an updated version. The reason for some non-standard code you found is that the Planyo module is also meant to be used independently of the Drupal system.

1. The reason for this is that ulap.php is called from Javascript via AJAX so I'm not sure if I can use drupal's functions in there (this is not within drupal's framework). This wouldn't be necessary if AJAX allowed calls to other domains. Otherwise a simple proxy is required. Should I include includes/common.inc in ulap.php instead?
2. The functions have now been prefixed
3,4,5. fixed. Thanks for the info!

Cheers,
Rafael.

avpaderno’s picture

Status: Needs work » Needs review

The reason for this is that ulap.php is called from Javascript via AJAX so I'm not sure if I can use drupal's functions in there.

See what update.php, or cron.php do to initialize, and bootstrap Drupal. Both files calls Drupal functions, and you can adopt the same strategy for your code.

Remember to change the status, when you upload new code.

dave reid’s picture

Status: Needs review » Needs work

Best way to handle this is to use jQuery's built in AJAX method to request the 'js/planyo' path on your site, when executes one of your module's hook_menu() callbacks that uses drupal_http_request() to fetch the data. There are plenty of examples on api.drupal.org (search for 'autocomplet').

zwieciu’s picture

Status: Needs work » Needs review
StatusFileSize
new22.24 KB

Hi,

I have now followed Dave's suggestion and got rid of the ulap.php altogether, instead creating a new path 'planyo/ulap' which in turn calls drupal_http_request.

I'm changing the status to needs review as requested.

Cheers,
Rafael.

avpaderno’s picture

Status: Needs review » Needs work
if (MooTools.version == "1.11") {
  var JSON = Json;
  Json.encode = Json.toString;
  Json.decode = Json.evaluate;
}

Drupal doesn't come with Mootools; why doesn't the code use what jQuery offers?

avpaderno’s picture

function planyo_get_day_name (n, is_short) {
  var arr = isset (document.s_weekdays_short) ? (is_short ? document.s_weekdays_short : document.s_weekdays_med) :
    (is_short ? new Array ("M", "T", "W", "T", "F", "S", "S") : new Array ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"));
  return arr [n % 7];
}

function planyo_get_month_name (n, is_short) {
  var arr = isset (document.s_months_short) ? (is_short ? document.s_months_short : document.s_months_long) :
    (is_short ? new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") : new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"));
  return arr [n - 1];
}

Does JavaScript have a function called isset()?

planyo-utils.js is not using any jQuery function, but it is using DOM functions. Why doesn't the code use what jQuery makes available?

zwieciu’s picture

Status: Needs work » Needs review

Alberto,
Are you saying the module, in order to be accepted, cannot use Mootools? The reason for this is as mentioned before, the module is supposed to also work stand-alone or with other development tools. If this is a requirement, I can get rid of Mootools altogether and use jQuery instead, although this is rather problematic (would introduce need for multiple versions of code sent to the module from the planyo.com server via AJAX).

avpaderno’s picture

Status: Needs review » Needs work

I am just saying that I think difficult to persuade a user to download MooTools, when Drupal already comes with jQuery; it would be a not necessary requirement, and IMO it would be like write 10 custom functions that do the same task of existing 10 Drupal core functions, instead of using the existing Drupal functions.

The code could still work stand-alone, in the same way it works stand-alone using MooTools.

zwieciu’s picture

Status: Needs work » Needs review
StatusFileSize
new22.24 KB

OK, I have now completely updated the module as well as code returned by the server to work with jQuery instead of MooTools. See the attached version.

avpaderno’s picture

Status: Needs review » Needs work

function planyo_get_day_name (n, is_short) {
var arr = isset (document.s_weekdays_short) ? (is_short ? document.s_weekdays_short : document.s_weekdays_med) :
(is_short ? new Array ("M", "T", "W", "T", "F", "S", "S") : new Array ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"));
return arr [n % 7];
}

I think I have already reported about this.

function planyo_on_reservation_success(reservation_id, user_text) {
  document.getElementById('res_error_msg').style.display='none';
  document.getElementById('res_ok_msg').style.display='inline';
  document.getElementById('reserve_form').style.display='none';
  document.getElementById('price_info_div').style.display='none';
  document.getElementById('res_ok_msg').innerHTML = user_text;
}

What is wrong in that code?

zwieciu’s picture

StatusFileSize
new22.92 KB

I think I have already reported about this.

What exactly is the problem you see? As I wrote earlier, isset is a function defined in planyo-utils.js. The weekdays must be read this way because of different languages that can be used. To my knowledge there is no Javascript code that will give me short names of weekdays in Polish or Italian.

As for the other piece of code, I don't understand what problem you see there. I assume it's about using getElementById and style.display / innerHTML. I've changed this function and others I found using similar notation to the jQuery standard but please be clear about the changes that I must still make. The original code was valid javascript. Do you require using jQuery everywhere possible?

Cheers,
Rafael.

avpaderno’s picture

See what reported by Dave Reid:

Functions in utils.js aren't prefixed with the module shortname and might cause conflicts with other defined JS functions.

About not using the jQuery functions, see what Apply for contributions CVS access reports:

Your module pulls in a lot of JavaScript code in-line without a hint of jQuery involvement. Try to use jQuery to play nice with all the other jQuery code running on end users sites.

zwieciu’s picture

Status: Needs work » Needs review
StatusFileSize
new22.93 KB

Please find the updated version.

avpaderno’s picture

Status: Needs review » Needs work
  1. function planyo_show_hourglass(hide_element) {
      document.planyo_ajax_call_pending = true;
      if (hide_element) {
        document.planyo_ajax_call_hide_element = hide_element;
        hide_element.style.display = 'none';
        var parent = hide_element.parentNode;
        if (parent)
          var hourglass_element = document.createElement("div");
        hourglass_element.id = "hourglass_element";
        hourglass_element.innerHTML = "<img src='"+get_full_planyo_file_path("hourglass.gif")+"' align='middle' />";
        parent.insertBefore(hourglass_element, hide_element);
      }
    }
    
    function planyo_get_form_data(obj) {
      var getstr = "";
      for (var i=0; i<obj.childNodes.length; i++) {
        var tagName = obj.childNodes[i].tagName;
        if (tagName == "INPUT") {
          if (obj.childNodes[i].type == "text" || obj.childNodes[i].type == "hidden") {
    	getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
          }
          if (obj.childNodes[i].type == "checkbox") {
    	if (obj.childNodes[i].checked) {
    	  getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
    	} else {
    	  getstr += obj.childNodes[i].name + "=&";
    	}
          }
          if (obj.childNodes[i].type == "radio") {
    	if (obj.childNodes[i].checked) {
    	  getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
    	}
          }
        }   
        else if (tagName == "TEXTAREA") {
          getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
        }
    
        var picker = document.getElementById(document.current_picker);
        if (picker)
          old_date = Date.parse(picker.value);
      }
    

    The code is not using jQuery, as it should in such cases.

  2. function planyo_help($path, $arg) {
        switch ($path) {
    	case 'admin/help#planyo':
    	$output = '<p>'. t("This module embeds the Planyo.com online reservation system. Before using it, you'll need to create an account at planyo.com. Please see http://www.planyo.com/drupal-reservation-system for more info.") .'</p>';
    	return $output;
        }
    }
    
    function planyo_perm() {
        return array('access planyo', 'create planyo', 'administer planyo');
    }
    
    function planyo_admin() {
        $form = array();
    
        $form['planyo_site_id'] = array(
    	'#type' => 'textfield',
    	'#title' => t('Planyo site ID'),
    	'#default_value' => variable_get('planyo_site_id', 'demo'),
    	'#description' => t("ID of your planyo site. If you don't have a planyo site yet, create one first at www.planyo.com. The default value (demo) will use a demonstration site."),
    	'#required' => TRUE,
    	);
    
        $form['planyo_language'] = array(
    	'#type' => 'select',
    	'#title' => t('Language of Planyo interface'),
    	'#default_value' => variable_get('planyo_language', 'EN'),
    	'#description' => t('Choose of the supported languages (EN, FR, IT, ES, DE, PL, SE, FI, IS, DK)'),
    	'#options' => array('EN' => t('English'), 'FR' => t('French'), 'IT' => t('Italian'), 'ES' => t('Spanish'), 'DE' => t('German'), 'PL' => t('Polish'), 'SE' => t('Swedish'), 'DK' => t('Danish'), 'FI' => t('Finnish'), 'IS' => t('Icelandic')),
    	);
    

    See the Drupal coding standards to understand how a module code should be written. In particular see how the code should be formatted.

  3.     if (parse_url($url, PHP_URL_HOST) != "www.planyo.com")
          return "Error: Call to $url not allowed";
    

    The second parameter is accepted only in PHP 5, but the module doesn't declare it needs that PHP version. The code I reported is another example of code not conforming to the coding standards.

  4. 	foreach (array_keys($fields) as $key) {
    	    $data = $data . "$key=" . rawurlencode($fields[$key]);
    	    $data .= '&';
    	}
    

    The code should use drupal_urlencode().

zwieciu’s picture

Status: Needs work » Needs review
StatusFileSize
new22.4 KB

Hi Alberto,

Thanks for your feedback. I really appreciate your patience and help with this. I'm posting the updated version that fixes all the issues mentioned by you:
- jQuery is used very heavily (in all places I could find). No more document.getElementById or document.createElement. The code is now also shorter because of these changes
- I've thoroughly read and implemented the coding standards and verified with the coder module using the minor level warings. I noticed all other modules (including coder :)) have lots of warnings, though
- the parse_url has been fixed (it was already fixed before but I forgot to update the module submitted last time)
- drupal_urlencode is used instead of rawurlencode
- files are tagged with // $Id$

Cheers,
Rafael.

solona’s picture

This module doesn't seem to specify which version of Drupal it's compatible with.

avpaderno’s picture

Status: Needs review » Needs work

@teremka: The module specifies the version of Drupal it requires.

    '#description' => t('ID of your planyo site. If you don\'t have a ' .
    'planyo site yet, create one first at ' .
    'www.planyo.com. The default value (demo) will use ' .
    'a demonstration site.'),

The first argument of t() is a literal string, not a dynamic value; differently, the script to extract the strings to translate will not extract the string. Avoid also to escape the quote inside the strings that are passed to t().

planyo_content() should use drupal_add_js() to add the JavaScript code (which should be in an external file), and to pass values to that script (see http://api.drupal.org/api/function/drupal_add_js/6 to understand exactly how that is done).

zwieciu’s picture

Status: Needs work » Needs review
StatusFileSize
new22.29 KB

OK, the strings are reverted back to the single text without escape characters. I thought about using the multiple-line version but I don't think this would be what was intended to be passed to the t() function.

drupal_add_js() is now used to output script code in planyo_content(). Some of the calls needed to be left inline because the data comes from the module settings.

avpaderno’s picture

Status: Needs review » Needs work

http://api.drupal.org/api/function/drupal_add_js/6 reports how to pass values to Javascript code (which is not what the module is doing).
The tag <link> should be inside the tag <head>, and there is a Drupal function to add such tags.

zwieciu’s picture

Status: Needs work » Needs review
StatusFileSize
new22.12 KB

I have to admin the drupal api is incredibly rich and very well done!

The new version fixes these and some other javascript issues I found in the documentation.

Cheers,
Rafael.

avpaderno’s picture

Status: Needs review » Fixed
function planyo_perm() {
  return array('access content');
}

That permission is already declared from a Drupal core module; a module should declare its own permissions, not the permissions it uses.

I apologize for the delay in approving this application.

Thank you for your contribution! I am going to update your account.

These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the dedicated reviewers as well.

zwieciu’s picture

Thank you. The permissions have been changed. Still, by default the UI uses 'access content'. This used to be 'access planyo' earlier but some of the users were confused because by default (without changing permissions) the UI was not accessible to anonymous users.

Status: Fixed » Closed (fixed)
Issue tags: -Module review

Automatically closed -- issue fixed for 2 weeks with no activity.

avpaderno’s picture

Component: Miscellaneous » new project application
Assigned: Unassigned » avpaderno
Issue summary: View changes