New Excel Generation API

New Excel Generation API

by Eloy Lafuente (stronk7) -
Number of replies: 15
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi moodlers,

as part of the changes coming with Moodle 1.6, a new Excel Generation API has been created and all the scripts using the old one, have been updated to use it.

Technically, it replaces the old "lib/excel/*" files and use their current evolution, as part of the PEAR package. But you can safely, ignore this. From Moodle 1.6, we will always generate Excel files by using the new "lib/excellib.class.php" wrapper classes, so changes in internal used libraries (i.e. PEAR for now) won't affect our code anymore.

Basically, all we need to write Excel files is:
    require_once($CFG->libdir.'/excellib.class.php');
/// Calculate file name
$downloadfilename = clean_filename("thenameofthefile.xls");
/// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
/// Sending HTTP headers
$workbook->send($downloadfilename);
/// Adding the worksheet
$myxls =& $workbook->add_worksheet($strgrades);
/// Print cellls
$myxls->write_string(0,0,"Hello"));
$myxls->write_string(0,1,"Bye"));
/// Close the workbook
$workbook->close();


It supports some basic formatting (colours, borders, numbers...) and should work pretty well under any encoding (because, internally, everything is converted to UTF-16LE, that is a native supported encoding for excel files. The new classes are self-documented (PHP-Doc, I think) and should be easy to understand.

So, if we haven't forgot anything, all the current "excel generators" inside Moodle 1.6dev (gradebook, quiz reports, choice, hotpot, survey...) should be working properly using the new API. Please, update your code to use it. And test everything works as expected, reporting any problem you find.

Ciao smile
Average of ratings: -
In reply to Eloy Lafuente (stronk7)

Re: New Excel Generation API

by Jamie Pratt -
Is there possibly a problem distributing pear libraries as part of Moodle?

PEAR libraries are licensed under the PHP license which is listed on the gnu.org web site as being incompatible with the GPL license.


In reply to Jamie Pratt

Re: New Excel Generation API

by Brian Sea -
Yes, this would be a problem if the PEAR libraries are distributed with Moodle.

My suggestion is that you check for the external PEAR libs and if they don't exist to fall back to the old conversions. Implant some warnings for Moodle.. because I don't believe you can distribute the PEAR libs with Moodle due to license problems mixed
In reply to Brian Sea

Re: New Excel Generation API

by Dirk Herr-Hoyman -
Perhaps I'm missing something, but my reading of the PEAR licence is that
it's got the same terms as PHP. See http://pear.php.net/copyright.php
If the PHP license is a problem, then there is a much larger issue here
for Moodle. As well as quite a few other open source apps written in PHP smile

Of course the prudent thing to do would be to check with the PEAR project,
the copyright holder, and get their permission and/or interpretation of their license.

In reply to Dirk Herr-Hoyman

Re: New Excel Generation API

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Hmm, after a bit of googling the way I see it is:
  • it is OK to use PHP licensed code from GPL program
  • it is not OK to distribute GNU+PHP licensed code as one product, because we would be violating the copyleft intention of the original GNU authors

Possible solutions:
  1. require PEAR packages installed on server or manual separate download - IMO too complicated for end users
  2. change licensing to allow PHP exception - there might be problems with GNU libraries and old code with unreachable authors
  3. use similar mechanism as for new lang packages in 1.6 - download PEAR files from net and extract them into data directory

In reply to Petr Skoda

Re: New Excel Generation API

by Brian Sea -
Correct.. distribution is the problem.

Option 3 seems to be okay;  Just couple it with option 1 where the older excel converters are used if the external PEAR libs aren't found - this is exactly what's done with the GD libs.
In reply to Petr Skoda

Re: New Excel Generation API

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi,

assuming that my legal knowledge of the licenses is really limited, from my perspective, all we are doing is to include 3 libraries from the PEAR project, two of them are governed by the PHP library where the third (the one we are using directly) is governed by the LGPL library.

After reading the PHP License, I cannot see anything against to include such libraries inside Moodle distro (it's open source, we aren't using the PHP name in our product and the literal "This product includes PHP software, freely available from " (point 6 of the license) can be filled in our credits page. So we are fulfilling PHP terms perfectly.

About GPL, well, Moodle code is GPL, sure, but the question is "Can GPL code work with other licenses of code?" And I really hope the answer was yes! Taking a quick look to the Credits Page it seems that we are using a lot of libraries with different licenses (GPL, LGPL, BSD, HowToCreate, htmlArea, Artistic...) and it hasn't been a problem in the past.

While all those licenses allow us to distribute, to modify and to use their code freely (fulfilling them completely, of course), I cannot see why they cannot be distributed, modified and used from Moodle GPL code. Obviously, such 3rd part code will be governed by their original license (they don't become GPL by being included in one GPL product!) and their users must fulfil them too. That's the reason to have all them well documented in the credits page. Moodle is fulfilling such licenses perfectly and moodlers too (by executing them).

So, if we aren't breaking the PHP license (nor anyone of the rest) and nothing forbids us to freely distribute and use such code, where is the problem? More yet, if the the PEAR package we are using is licensed under LGPL, how can this be problematic?

I must insist that it's my personal (own logic) opinion and perhaps there is something in the GPL (or PHP) licenses that breaks my assumptions, but I haven't been able to find it.

Ciao, one non expert lawyer smile
Average of ratings: Useful (1)
In reply to Eloy Lafuente (stronk7)

Re: New Excel Generation API

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I'm not a lawyer, but it seems to me the PHP license and the GPL license are not compatible. That doesn't mean one cannot use PHP to build GPL applications (i.e. use PHP). It justs means you cannot mix PHP code and GPL code in the same product, creating what's called a 'derivative work'.

The problem arises with pint 3 and 4 of the PHP licences, that imposes additional restrictions (naming restrictions in this case) to those found in the GPL license. And this is something the GPL license prohibits expressely. This is what initially prevented the mysql client inclusion in PHP 5.x, for example (this was later dealt with between the PHP Group and MySQL AB).

So as long as you are just using PHP (i.e., creating PHP scripts), you are on the safe side of the line.

On the other hand, PEAR packages can have several different licenses (each packages can choose between at leat 5 different ones), so we should check every PEAR package if it's license is compatible with GPL or not.

Saludos. Iñaki.
In reply to Eloy Lafuente (stronk7)

Re: New Excel Generation API

by Brian Sea -
"Can GPL code work with other licenses of code?"

The answer is yes.  However, the problem isn't with use, it's with distribution.   The PHP license is not one compatible with the GPL and since PHP4 is not dual-licensed under the GPL, you cannot distribute the two together pieces of software together.

"PHP License, Version 3.0 -This license is used by most of PHP4.  It is a non-copyleft
free software license which is incompatible with the GNU GPL."  -- Free Software Foundation

However, if Moodle were to add an exception to their GPL license to allow distribution with PHP licensed software (like mySQL does) then this particular combination is no longer an issue (though other problems might exist elsewhere).

"Optional GPL License Exception for PHP. As a special exception,
MySQL AB gives permission to distribute derivative works that are
formed with GPL-licensed MySQL software and with software licensed
under version 3.0 of the PHP license. You must obey the GNU General
Public License in all respects for all of the code used other than code
licensed under version 3.0 of the PHP license." -- mySQL License

As far as the other licenses:

BSD - The modified BSD license is compatible - but not the orginial.

LGPL - is compatible

Artistic - unknown (FSF says it's too vague to determine)


It all boils down to distribution.... If two licenses of a software bundle are incompatible, the the bundle cannot exist.  Therefore, if moodle has two pieces of software with incompatible licenses, then it cannot be distributed as one bundle. 

Sorry.
--sea


In reply to Brian Sea

Re: New Excel Generation API

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
>>"Can GPL code work with other licenses of code?"

>>The answer is yes.  However, the problem isn't with use, it's with distribution.



Ok. That's a nice start. We can use PHP licensed code. Great!

Now, the distribution: If we include some PHP licensed code inside Moodle (exactly the lib/pear dir currently in 1.6dev) we aren't infringing the PHP license at all (it's OpenSource approved so distribution is allowed without problems at all). More if we are including such license in the distribution and we show it properly in the credits page). So distribution of that PHP licensed code isn't the problem. Cool!

The problem seems to be what happens with Moodle's GPL license itself (because now, the distribution will include some parts that are not GPL). Is this the key problem?

In a logic world, I really think that providing correct information about what's Moodle code (GPL) and what's non-Moodle code (PHP, LGPL, BSD...) should be enough. And that's exactly what the credits page inform about. All the Moodle code is GPL whereas 3rd part libraries can have other licenses (OpenSource too). Why Moodle's license has to be changed because it uses some code under a different license? Really, I don't see the problem (where is the OpenSource - not FSF - Spirit?).

Anyway, if we need to separate it from official distros, well, it can be done, sure. Although I cannot see the problem in my OpenSourceMind... tongueout

Ciao smile
In reply to Jamie Pratt

Re: New Excel Generation API

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Sigh, major bummer. sad I don't want to change the license or mess with the GPL in any way, and there will probably be more PEAR libraries that we'll want to use in future.

After some thought, I think what we need to do is:
  1. Take "our" PEAR libraries out of cvs:/moodle/lib/pear and put them in cvs:/pear as a separate module
  2. Add a check to the admin page (and installation) to check for the presence of system PEAR libraries, or files in cvs:/moodle/lib/pear.
  3. If they aren't there, then download a separate package from moodle.org containing all our own local PEAR libraries and put them in dataroot/lib/pear.
  4. Make sure that the best one of these is loaded! smile
Any problems with that?
In reply to Martin Dougiamas

Re: New Excel Generation API

by Martín Langhoff -
No problems from this corner.

As people have pointed out, there is a minor conflict. The truth is that the PHP-licensed side cannot complain (unless we rename Moodle to PHPlearn) so we should ask the guy who owns the copyright on the GPL'd code if he actually minds.

From config-dist.php:

> Copyright (C) 1999-2004 Martin Dougiamas http://dougiamas.com

smile

(Don't take me seriously, there are more owners here involved: AdoDB, all other CVS committers, etc).

Now, strictly speaking... PHPNuke and PHPGallery are in straight conflict with the PEAR license, and anyone who distributes them bundled with PHP (like RedHat or Debian do) is in violation of the PHP license. I really do hope that PEAR and PHP licenses _drop_ that clause -- trademark law has its own weight, and doesn't need to hinge on copyright law.
In reply to Eloy Lafuente (stronk7)

Re: New Excel Generation API

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Wow, you updated the HotPot module already. Thanks very much Eloy approve
Gordon
In reply to Gordon Bateson

Re: New Excel Generation API

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Yeah, it was the most complex to do! And it forced us to include all those "decoration" functions (borders, colours...). cool

Anyway, plz, check it with big results, I only tested it with a really small collection of data...

Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: New Excel Generation API

by Ivan Veretelnyk -
Hello All.

Does anyone know how to copy this file to another folder?
I don't need to force download, I need to access directly to file and copy it to another folder on my server.

Thanks
Ivan