commit b02d70adf0f751bdd68269513093573f775abb0f
Author: Deon George
Date: Thu Oct 10 13:44:53 2013 +1100
Open Source Billing
diff --git a/.htaccess b/.htaccess
new file mode 100644
index 00000000..c8dada9c
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,21 @@
+# Turn on URL rewriting
+RewriteEngine On
+
+# Installation directory
+RewriteBase /
+
+# Protect hidden files from being viewed
+
+ Order Deny,Allow
+ Deny From All
+
+
+# Protect application and system files from being viewed
+RewriteRule ^(?:application|modules|includes/kohana)\b.* index.php/$0 [L]
+
+# Allow any files or directories that exist to be displayed directly
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+
+# Rewrite all other URLs to index.php/URL
+RewriteRule .* index.php/$0 [PT]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..94a9ed02
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/application/bootstrap.php b/application/bootstrap.php
new file mode 100644
index 00000000..02f72632
--- /dev/null
+++ b/application/bootstrap.php
@@ -0,0 +1,169 @@
+"
+ */
+if (isset($_SERVER['KOHANA_ENV']))
+{
+ Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
+}
+
+/**
+ * Initialize Kohana, setting the default options.
+ *
+ * The following options are available:
+ *
+ * - string base_url path, and optionally domain, of your application NULL
+ * - string index_file name of your index file, usually "index.php" index.php
+ * - string charset internal character set used for input and output utf-8
+ * - string cache_dir set the internal cache directory APPPATH/cache
+ * - integer cache_life lifetime, in seconds, of items cached 60
+ * - boolean errors enable or disable error handling TRUE
+ * - boolean profile enable or disable internal profiling TRUE
+ * - boolean caching enable or disable internal caching FALSE
+ * - boolean expose set the X-Powered-By header FALSE
+ */
+Kohana::init(array(
+ 'base_url' => '/',
+ 'caching' => TRUE,
+ 'index_file' => '',
+));
+
+/**
+ * Attach the file write to logging. Multiple writers are supported.
+ */
+Kohana::$log->attach(new Log_File(APPPATH.'logs'));
+
+/**
+ * Attach a file reader to config. Multiple readers are supported.
+ */
+Kohana::$config->attach(new Config_File);
+
+/**
+ * Enable modules. Modules are referenced by a relative or absolute path.
+ */
+Kohana::modules(array(
+ 'lnapp' => MODPATH.'lnApp',
+ 'auth' => SMDPATH.'auth', // Basic authentication
+ 'cache' => SMDPATH.'cache', // Caching with multiple backends
+ 'cron' => SMDPATH.'cron', // Kohana Cron Module
+ // 'codebench' => SMDPATH.'codebench', // Benchmarking tool
+ 'database' => SMDPATH.'database', // Database access
+ 'gchart' => MODPATH.'gchart', // Google Chart Module
+ // 'image' => SMDPATH.'image', // Image manipulation
+ 'khemail' => SMDPATH.'khemail', // Email module for Kohana 3 PHP Framework
+ 'minion' => SMDPATH.'minion', // CLI Tasks
+ 'orm' => SMDPATH.'orm', // Object Relationship Mapping
+ 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework
+ // 'unittest' => SMDPATH.'unittest', // Unit testing
+ // 'userguide' => SMDPATH.'userguide', // User guide and API documentation
+ 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework
+ ));
+
+/**
+ * Load our modules defined in the DB
+ */
+Kohana::modules(array_merge(Kohana::modules(),Config::modules()));
+
+/**
+ * Enable specalised interfaces
+ */
+Route::set('sections', '/(/(/(/)))',
+ array(
+ 'directory' => '('.implode('|',array_values(URL::$method_directory)).')'
+ ))
+ ->defaults(array(
+ 'action' => 'index',
+ ));
+
+// Static file serving (CSS, JS, images)
+Route::set('default/media', 'media(/)', array('file' => '.+'))
+ ->defaults(array(
+ 'controller' => 'media',
+ 'action' => 'get',
+ ));
+
+/**
+ * Set the routes. Each route must have a minimum of a name, a URI and a set of
+ * defaults for the URI.
+ */
+Route::set('default', '((/(/)))', array('id'=>'[a-zA-Z0-9_.-]+'))
+ ->defaults(array(
+ 'controller' => 'welcome',
+ 'action' => 'index',
+ ));
+
+/**
+ * If APC is enabled, and we need to clear the cache
+ */
+if (file_exists(APPPATH.'cache/CLEAR_APC_CACHE') AND function_exists('apc_clear_cache') AND (PHP_SAPI !== 'cli')) {
+ if (! apc_clear_cache() OR ! unlink(APPPATH.'cache/CLEAR_APC_CACHE'))
+ throw new Kohana_Exception('Unable to clear the APC cache.');
+}
+?>
diff --git a/application/cache/.htaccess b/application/cache/.htaccess
new file mode 100644
index 00000000..281d5c33
--- /dev/null
+++ b/application/cache/.htaccess
@@ -0,0 +1,2 @@
+order allow,deny
+deny from all
diff --git a/application/classes/Auth/ORM.php b/application/classes/Auth/ORM.php
new file mode 100644
index 00000000..4f44b9b2
--- /dev/null
+++ b/application/classes/Auth/ORM.php
@@ -0,0 +1,22 @@
+_config['hash_method']) {
+ case '' : return $str;
+ case 'md5': return md5($str);
+ default: return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
+ }
+ }
+}
+?>
diff --git a/application/classes/Auth/OSB.php b/application/classes/Auth/OSB.php
new file mode 100644
index 00000000..3f2e01d2
--- /dev/null
+++ b/application/classes/Auth/OSB.php
@@ -0,0 +1,275 @@
+action ($role == TRUE)
+ *
+ * @param boolean If authentication should be done for this module:method (ie: controller:action).
+ * @return boolean
+ */
+ public function logged_in($role=NULL,$debug=NULL) {
+ $status = FALSE;
+
+ // Get the user from the session
+ $uo = $this->get_user();
+
+ // If we are not a valid user object, then we are not logged in
+ if (is_object($uo) AND ($uo instanceof Model_Account) AND $uo->loaded()) {
+ if (Config::sitemode() == Kohana::DEVELOPMENT)
+ SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Debug::vars(array('user'=>$uo->username,'r'=>$role))));
+
+ if (! empty($role)) {
+ // Get the module details
+ $mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
+ if (! $mo->loaded() OR ! $mo->status) {
+ SystemMessage::add(array(
+ 'title'=>'Module is not defined or active in the Database',
+ 'type'=>'warning',
+ 'body'=>sprintf('Module not defined: %s',Request::current()->controller()),
+ ));
+
+ } else {
+ if (Request::current()->directory())
+ $method_name = sprintf('%s_%s',Request::current()->directory(),Request::current()->action());
+ else
+ $method_name = Request::current()->action();
+
+ // Get the method number
+ $mmo = ORM::factory('Module_Method',array('module_id'=>$mo->id,'name'=>$method_name));
+ if (! $mmo->loaded()) {
+ SystemMessage::add(array(
+ 'title'=>'Method is not defined or active in the Database',
+ 'type'=>'warning',
+ 'body'=>sprintf('Method not defined: %s for %s',Request::current()->action(),$mo->name),
+ ));
+
+ } else {
+ // If the role has the authorisation to run the method
+ $gmo = ORM::factory('Group_Method')
+ ->where('method_id','=',$mmo->id);
+
+ $roles = '';
+ foreach ($gmo->find_all() as $gm) {
+ $roles .= ($roles ? '|' : '').$gm->group->name;
+
+ // $gm->group->id == 0 means all users.
+ if ($gm->group->id == 0 OR $uo->has_any('group',$gm->group->list_childgrps(TRUE))) {
+ $status = TRUE;
+ $roles = '';
+
+ break;
+ }
+ }
+
+ if (! $status) {
+ if (Config::sitemode() == Kohana::DEVELOPMENT)
+ SystemMessage::add(array(
+ 'title'=>'User is not authorised in Database',
+ 'type'=>'debug',
+ 'body'=>sprintf('Role(s) checked: %s User: %sModule: %s Method: %s',$roles,$uo->username,$mo->name,$mmo->name),
+ ));
+ }
+ }
+ }
+
+ if (Config::sitemode() == Kohana::DEVELOPMENT)
+ SystemMessage::add(array(
+ 'title'=>'Debug',
+ 'type'=>'debug',
+ 'body'=>sprintf('User: %s, Module: %s, Method: %s, Role: %s, Status: %s, Data: %s',
+ $uo->username,Request::current()->controller(),Request::current()->action(),$role,$status,$debug)));
+
+ // There is no role, so the method should be allowed to run as anonymous
+ } else {
+ if (Config::sitemode() == Kohana::DEVELOPMENT)
+ SystemMessage::add(array(
+ 'title'=>'Debug',
+ 'type'=>'debug',
+ 'body'=>sprintf('User: %s, Module: %s, Method: %s, Status: %s, Data: %s',
+ $uo->username,Request::current()->controller(),Request::current()->action(),'No Role Default Access',$debug)));
+
+ $status = TRUE;
+ }
+
+ } else {
+ if (Config::sitemode() == Kohana::DEVELOPMENT)
+ SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>'No user logged in'));
+ }
+
+ return $status;
+ }
+
+ /**
+ * Gets the currently logged in user from the session.
+ * Returns NULL if no user is currently logged in.
+ *
+ * @param boolean Check token users too
+ * @return mixed
+ */
+ public function get_user($default=NULL,$tokenuser=TRUE) {
+ // Get the current user
+ $uo = parent::get_user($default);
+
+ // If we are not logged in, see if there is token for the user
+ if (is_null($uo) AND $tokenuser AND ($token=Session::instance()->get('token')) OR (! empty($_REQUEST['token']) AND $token=$_REQUEST['token']))
+ $uo = $this->_get_token_user($token);
+
+ return $uo;
+ }
+
+ /**
+ * Get the user that a token applies to
+ *
+ * This will check that the token is valid (not expired and for the request)
+ *
+ * @param $token The token
+ * @return Model_Account|NULL The user that the token is valid for.
+ */
+ private function _get_token_user($token) {
+ // This has been implemented, as we sometimes we seem to come here twice
+ static $uo = NULL;
+
+ if (! is_null($uo))
+ return $uo;
+
+ $mmto = ORM::factory('Module_Method_Token',array('token'=>$token));
+
+ // Ignore the token if it doesnt exist.
+ if ($mmto->loaded()) {
+ // Check that the token is for this URI
+ $mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
+ $mmo = ORM::factory('Module_Method',array(
+ 'module_id'=>$mo->id,
+ 'name'=>Request::current()->directory() ? sprintf('%s_%s',Request::current()->directory(),Request::current()->action()) : Request::current()->action()
+ ));
+
+ // Ignore the token if this is not the right method.
+ if ($mmo->id == $mmto->method_id) {
+ if (! is_null($mmto->date_expire) AND $mmto->date_expire < time()) {
+ SystemMessage::add(array(
+ 'title'=>_('Token Not Valid'),
+ 'type'=>'warning',
+ 'body'=>_('Token expired')));
+
+ // @todo Log the token deletion
+ Session::instance()->delete('token');
+ $mmto->delete();
+
+ } elseif (! is_null($mmto->uses) AND $mmto->uses < 1) {
+ SystemMessage::add(array(
+ 'title'=>_('Token Not Valid'),
+ 'type'=>'warning',
+ 'body'=>_('Token expired')));
+
+ // @todo Log the token deletion
+ Session::instance()->delete('token');
+ $mmto->delete();
+
+ } else {
+ // If this is a usage count token, reduce the count.
+ if (! is_null($mmto->uses))
+ $mmto->uses -= 1;
+
+ // Record the date this token was used
+ $mmto->date_last = time();
+ $mmto->save();
+
+ Session::instance()->set('token',$token);
+
+ $uo = ORM::factory('Account',$mmto->account_id);
+ $uo->log(sprintf('Token %s used for method %s [%s]',$mmto->token,$mmto->module_method->name(),Request::current()->param('id')));
+ }
+ }
+ }
+
+ return $uo;
+ }
+
+ /**
+ * Logs a user in.
+ *
+ * @param string username
+ * @param string password
+ * @param boolean enable autologin
+ * @return boolean
+ */
+ protected function _login($user,$password,$remember) {
+ if (! is_object($user)) {
+ $username = $user;
+
+ // Load the user
+ $user = ORM::factory('Account');
+ $user->where('username','=',$username)->find();
+
+ // If no user loaded, return
+ if (! $user->loaded())
+ return FALSE;
+ }
+
+ // Create a hashed password
+ if (is_string($password))
+ $password = $this->hash($password);
+
+ // If the passwords match, perform a login
+ if ($user->status AND $user->has_any('group',ORM::factory('Group',array('name'=>'Registered Users'))->list_childgrps(TRUE)) AND $user->password === $password) {
+
+ // @todo This is not currently used.
+ if ($remember === TRUE) {
+ // Create a new autologin token
+ $token = ORM::factory('User_Token');
+
+ // Set token data
+ $token->user_id = $user->id;
+ $token->expires = time() + $this->_config['lifetime'];
+ $token->save();
+
+ // Set the autologin cookie
+ Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
+ }
+
+ // Record our session ID, we may need to update our DB when we get a new ID
+ $oldsess = session_id();
+
+ // Finish the login
+ $this->complete_login($user);
+
+ // Do we need to update databases with our new sesion ID
+ $sct = Kohana::$config->load('config')->session_change_trigger;
+ if (session_id() != $oldsess AND count($sct))
+ foreach ($sct as $t => $c)
+ if (Config::module_exist($t))
+ foreach (ORM::factory(ucwords($t))->where($c,'=',$oldsess)->find_all() as $o)
+ $o->set('session_id',session_id())
+ ->update();
+
+ return TRUE;
+ }
+
+ // Login failed
+ return FALSE;
+ }
+
+ /**
+ * Determine if a user is authorised to view an account
+ *
+ * @param Model_Account Account Ojbect to validate if the current user has access
+ * @return boolean TRUE if authorised, FALSE if not.
+ */
+ public function authorised(Model_Account $ao) {
+ return (($uo = $this->get_user()) AND $uo->loaded() AND ($uo == $ao OR in_array($ao->id,$uo->RTM->customers($uo->RTM))));
+ }
+}
+?>
diff --git a/application/classes/Company.php b/application/classes/Company.php
new file mode 100644
index 00000000..42d20934
--- /dev/null
+++ b/application/classes/Company.php
@@ -0,0 +1,139 @@
+so = $so;
+
+ if (! $this->so->loaded())
+ throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http')));
+
+ Kohana::$environment = (int)$this->so->status;
+ }
+
+ public static function instance() {
+ return new Company(ORM::factory('Setup',array('url'=>URL::base('http'))));
+ }
+
+ public function admin() {
+ return $this->so->account->name();
+ }
+
+ public function address($ln=' ') {
+ return implode($ln,array($this->street($ln),sprintf('%s, %s %s',$this->city(),$this->state(),$this->pcode())));
+ }
+
+ public function city() {
+ return $this->so->site_details('city');
+ }
+
+ public function contacts() {
+ return 'Tel: '.$this->phone();
+ }
+
+ public function country() {
+ return $this->so->country;
+ }
+
+ public function date_format() {
+ return $this->so->date_format;
+ }
+
+ public function decimals() {
+ return $this->so->decimal_place;
+ }
+
+ public function email() {
+ return $this->so->site_details('email');
+ }
+
+ public function fax() {
+ return $this->so->site_details('fax');
+ }
+
+ public function language() {
+ return $this->so->language->iso;
+ }
+
+ public function logo() {
+ return Config::logo();
+ }
+
+ public function logo_file() {
+ list ($path,$suffix) = explode('.',Config::$logo);
+
+ return ($x=Kohana::find_file(sprintf('media/site/%s',$this->site()),$path,$suffix)) ? $x : Kohana::find_file('media',$path,$suffix);
+ }
+
+ public function name() {
+ return $this->so->site_details('name');
+ }
+
+ public function module_config($item) {
+ return $this->so->module_config($item);
+ }
+
+ public function pcode() {
+ return $this->so->site_details('pcode');
+ }
+
+ public function phone() {
+ return $this->so->site_details('phone');
+ }
+
+ public function site($format=FALSE) {
+ return $format ? sprintf('%02s',$this->so->id) : $this->so->id;
+ }
+
+ public function so() {
+ return $this->so;
+ }
+
+ public function state() {
+ return $this->so->site_details('state');
+ }
+
+ public function street($ln=' ') {
+ return $this->so->site_details('address2') ? implode($ln,array($this->so->site_details('address1'),$this->so->site_details('address2'))) : $this->so->site_details('address1');
+ }
+
+ public function sitemode() {
+ return $this->so->status;
+ }
+
+ public function taxid() {
+ // Tax ID details are stored in invoice config
+ $mc = $this->so->module_config('invoice');
+
+ if (empty($mc['TAX_ID_NAME']))
+ return empty($mc['TAX_ID']) ? '' : $mc['TAX_ID'];
+ else
+ return sprintf('%s: %s',$mc['TAX_ID_NAME'],empty($mc['TAX_ID']) ? '' : $mc['TAX_ID']);
+ }
+
+ public function time_format() {
+ return $this->so->time_format;
+ }
+
+ public static function bsb() {
+ // @todo Details should be obtained from DB
+ return Kohana::$config->load('config')->bsb;
+ }
+
+ public static function account() {
+ // @todo Details should be obtained from DB
+ return Kohana::$config->load('config')->accnum;
+ }
+}
+?>
diff --git a/application/classes/Config.php b/application/classes/Config.php
new file mode 100644
index 00000000..45ee3119
--- /dev/null
+++ b/application/classes/Config.php
@@ -0,0 +1,177 @@
+load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type;
+ }
+
+ public static function copywrite() {
+ return '(c) Open Source Billing Development Team';
+ }
+
+ public static function country() {
+ return Company::instance()->country();
+ }
+
+ public static function date($date) {
+ return date(Company::instance()->date_format(),($date ? $date : time()));
+ }
+
+ /**
+ * Show a date using a site configured format
+ * @note We need this function here, since we call static:: methods, which need to resolve to the child class.
+ */
+ public static function datetime($date) {
+ return sprintf('%s %s',static::date($date),static::time($date));
+ }
+
+ public static function language() {
+ return Company::instance()->language();
+ }
+
+ /**
+ * The URI to show for the login prompt.
+ * Normally if the user is logged in, we can replace it with something else
+ */
+ public static function login_uri() {
+ return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor(URL::link('user','account/edit'),$ao->name()) : HTML::anchor('login',_('Login'));
+ }
+
+ public static function logo() {
+ return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
+ }
+
+ public static function logo_uri($protocol=NULL) {
+ list ($path,$suffix) = explode('.',static::$logo);
+
+ return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),$protocol);
+ }
+
+ /**
+ * Find a list of all database enabled modules
+ *
+ * Our available modules are defined in the DB (along with method
+ * security).
+ */
+ public static function modules() {
+ static $result = array();
+
+ if (! count($result)) {
+ // We need to know our site here, so that we can subsequently load our enabled modules.
+ if (PHP_SAPI === 'cli') {
+ if (! $site = Minion_CLI::options('site'))
+ // @todo Need to figure out how to make this CLI error nicer.
+ throw new Minion_Exception_InvalidTask(_('Cant figure out the site, use --site= for CLI'));
+ else
+ $_SERVER['SERVER_NAME'] = $site;
+ }
+
+ foreach (ORM::factory('Module')->list_external() as $mo)
+ $result[$mo->name] = MODPATH.$mo->name;
+ }
+
+ return $result;
+ }
+
+ public static function module_config($item) {
+ return Company::instance()->module_config($item);
+ }
+
+ public static function module_exist($module) {
+ return array_key_exists(strtolower($module),static::modules()) ? TRUE : FALSE;
+ }
+
+ public static function siteid($format=FALSE) {
+ return Company::instance()->site($format);
+ }
+
+ /**
+ * Work out our site mode (dev,test,prod)
+ */
+ public static function sitemode() {
+ return Company::instance()->sitemode();
+ }
+
+ public static function sitename() {
+ return Company::instance()->name();
+ }
+
+ /**
+ * See if our emails for the template should be sent to configured admin(s)
+ *
+ * @param string template - Template to test for
+ * @return mixed|array - Email to send test emails to
+ */
+ public static function testmail($template) {
+ $config = Kohana::$config->load('config')->email_admin_only;
+
+ if (is_null($config) OR ! is_array($config) OR empty($config[$template]))
+ return FALSE;
+ else
+ return $config[$template];
+ }
+
+ public static function theme() {
+ // If we are using user admin pages (and login), we'll choose the admin theme.
+ if (! empty(URL::$method_directory[strtolower(Request::current()->directory())]) OR in_array(strtolower(Request::current()->controller()),array('login')))
+ return 'theme/'.Kohana::$config->load('config')->theme_admin;
+ else
+ return 'theme/'.Kohana::$config->load('config')->theme;
+ }
+
+ public static function time($date) {
+ return date(Company::instance()->time_format(),($date ? $date : time()));
+ }
+}
+?>
diff --git a/application/classes/Controller/Account.php b/application/classes/Controller/Account.php
new file mode 100644
index 00000000..4f68068d
--- /dev/null
+++ b/application/classes/Controller/Account.php
@@ -0,0 +1,33 @@
+ao->group->find_all();
+
+ foreach ($cg as $go) {
+ $output .= sprintf('Group %s: %s ',$go->id,$go->display('name'));
+
+ foreach ($go->list_childgrps(TRUE) as $cgo)
+ $output .= sprintf('- %s: %s (%s) ',$cgo->id,$cgo->display('name'),$cgo->parent_id);
+
+ $output .= sprintf('END Group %s
',$go->id);
+ }
+
+ Block::add(array(
+ 'title'=>'Group Structure',
+ 'body'=>$output,
+ ));
+ }
+}
+?>
diff --git a/application/classes/Controller/Admin/Account.php b/application/classes/Controller/Admin/Account.php
new file mode 100644
index 00000000..213d70ff
--- /dev/null
+++ b/application/classes/Controller/Admin/Account.php
@@ -0,0 +1,17 @@
+FALSE, // @todo Testing
+ );
+}
+?>
diff --git a/application/classes/Controller/Admin/Module.php b/application/classes/Controller/Admin/Module.php
new file mode 100644
index 00000000..eac83967
--- /dev/null
+++ b/application/classes/Controller/Admin/Module.php
@@ -0,0 +1,130 @@
+TRUE,
+ 'edit'=>TRUE,
+ 'list'=>TRUE,
+ );
+
+ /**
+ * Get the list of methods for a class
+ */
+ protected function _methods($class) {
+ // Get a list of methods this module has
+ $ch = 'Controller_%s';
+ $methods = array();
+
+ // List of classes where all our methods are, including this one.
+ $classes = URL::$method_directory;
+ array_unshift($classes,'');
+
+ foreach ($classes as $c) {
+ $cn = Kohana::classname('Controller_'.$c ? $c.'_'.$class : $class);
+
+ if (class_exists($cn)) {
+ $r = new ReflectionClass($cn);
+
+ foreach ($r->getMethods() as $method)
+ if (preg_match('/^Controller_(.*_)?'.$class.'$/i',$method->class) AND ! preg_match('/^_/',$method->name))
+ array_push($methods,str_replace('action_',($c ? $c.'_' : $c),$method->name));
+ }
+ }
+
+ return $methods;
+ }
+
+ /**
+ * List our installed modules
+ */
+ public function action_list() {
+ $mo = ORM::factory('Module');
+
+ Block::add(array(
+ 'title'=>_('Defined Modules'),
+ 'body'=>Table::display(
+ $mo->find_all(),
+ 25,
+ array(
+ 'id'=>array('label'=>'ID','url'=>URL::link('admin','module/edit/')),
+ 'name'=>array('label'=>'Name'),
+ 'status'=>array('label'=>'Active'),
+ ),
+ array(
+ 'page'=>TRUE,
+ 'type'=>'list',
+ )),
+ ));
+ }
+
+ /**
+ * Edit a Module Configuration
+ *
+ * @todo Highlight those methods that have security, but the class does not have auth_required set to YES or the method isnt defined in secure_actions
+ */
+ public function action_edit() {
+ $mid = $this->request->param('id');
+ $mo = ORM::factory('Module',$mid);
+
+ if (! $mo->loaded()) {
+ SystemMessage::add(array(
+ 'title'=>_('Invalid Module ID'),
+ 'type'=>'error',
+ 'body'=>sprintf(_('Module with ID %s doesnt appear to exist?'),$mid),
+ ));
+
+ return;
+ }
+
+ $output = '';
+ $methods = $this->_methods($mo->name);
+
+ // Show methods defined in the DB already.
+ Block::add(array(
+ 'title'=>sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')),
+ 'body'=>Table::display(
+ $mo->module_method->find_all(),
+ 25,
+ array(
+ 'id'=>array('label'=>'ID','url'=>URL::link('admin','module_method/edit/')),
+ 'name'=>array('label'=>'Name'),
+ 'notes'=>array('label'=>'Notes'),
+ 'menu_display'=>array('label'=>'Menu'),
+ ),
+ array(
+ 'page'=>TRUE,
+ 'type'=>'list',
+ )),
+ ));
+
+ // Show new methods NOT defined in the DB already.
+ foreach ($mo->module_method->find_all() as $meo)
+ if (($method = array_search($meo->name,$methods)) !== false)
+ unset($methods[$method]);
+
+ if (count($methods))
+ Block::add(array(
+ 'title'=>sprintf('%s: %s ',_('Undefined Module Methods For'),$mo->display('name')),
+ 'body'=>Table::display(
+ $methods,
+ 25,
+ array(
+ '__VALUE__'=>array('label'=>'Name','url'=>URL::link('admin','module_method/add/'.$mo->id)),
+ ),
+ array(
+ 'page'=>TRUE,
+ 'type'=>'list',
+ )),
+ ));
+ }
+}
+?>
diff --git a/application/classes/Controller/Admin/Module/Method.php b/application/classes/Controller/Admin/Module/Method.php
new file mode 100644
index 00000000..95fcc9d9
--- /dev/null
+++ b/application/classes/Controller/Admin/Module/Method.php
@@ -0,0 +1,137 @@
+request->param('id');
+ $method = $this->request->param('sid');
+
+ $mo = ORM::factory('Module',$id);
+ $mmo = ORM::factory('Module_Method');
+
+ if (! $mo->loaded() OR ! in_array($method,$this->_methods($mo->name)))
+ throw new Kohana_Exception('Method (:method) does not exist in :class',array(':method'=>$method,':class'=>$mo->name));
+
+ $mmo->name = $method;
+ $mmo->module_id = $mo->id;
+ $mmo->values($_POST);
+
+ $output = '';
+
+ if ($_POST AND $mmo->values($_POST)->check()) {
+ $mmo->save();
+
+ if ($mmo->saved()) {
+ SystemMessage::add(array(
+ 'title'=>_('Method Added'),
+ 'type'=>'info',
+ 'body'=>sprintf(_('Method %s defined to database'),$mmo->name),
+ ));
+
+ HTTP::redirect(URL::link('admin','/module/edit/'.$mo->id));
+
+ } else {
+ SystemMessage::add(array(
+ 'title'=>_('Method Not Saved'),
+ 'type'=>'error',
+ 'body'=>sprintf(_('Unable to define Method %s to database?'),$mmo->name),
+ ));
+ }
+ }
+
+ $output .= View::factory('module/admin/method_add')
+ ->set('module',$mo)
+ ->set('method',$mmo);
+
+ Block::add(array(
+ 'title'=>sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($mmo->name),strtoupper($mo->name)),
+ 'body'=>$output,
+ ));
+ }
+
+ /**
+ * Edit a Module Configuration
+ *
+ * @param int $mid Module ID
+ */
+ public function action_edit() {
+ $mid = $this->request->param('id');
+ $mmo = ORM::factory('Module_Method',$mid);
+
+ if (! $mmo->loaded()) {
+ SystemMessage::add(array(
+ 'title'=>_('Invalid Method ID'),
+ 'type'=>'error',
+ 'body'=>sprintf(_('Method with ID %s doesnt appear to exist?'),$mid),
+ ));
+
+ return;
+ }
+
+ $output = '';
+
+ // The groups that can run this method.
+ $groups = ORM::factory('Group');
+
+ if ($_POST) {
+ foreach ($groups->find_all() as $go) {
+ // If the group was defined and no longer
+ if ($mmo->has('group',$go) AND (! isset($_POST['groups']) OR ! in_array($go->id,$_POST['groups']))) {
+ $gm = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
+
+ if (! $gm->delete())
+ SystemMessage::add(array(
+ 'title'=>_('Unable to DELETE Group Method'),
+ 'type'=>'error',
+ 'body'=>sprintf(_('Unable to delete Group Method for method %s and group %s'),$mmo->name,$go->name),
+ ));
+
+ // If the group was not defined and now is
+ } elseif (! $mmo->has('group',$go) AND isset($_POST['groups']) AND in_array($go->id,$_POST['groups'])) {
+ $gm = ORM::factory('Group_Method')
+ ->values(array(
+ 'method_id'=>$mmo->id,
+ 'group_id'=>$go->id,
+ ));
+
+ if (! $gm->check() OR ! $gm->save())
+ SystemMessage::add(array(
+ 'title'=>_('Unable to SAVE Group Method'),
+ 'type'=>'error',
+ 'body'=>sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name),
+ ));
+ }
+ }
+ }
+
+ $output .= Form::open();
+
+ $output .= View::factory('module/admin/method_detail_head');
+ foreach ($groups->find_all() as $go) {
+ $output .= View::factory('module/admin/method_detail_body')
+ ->set('group',$go)
+ ->set('defined',$mmo->has('group',$go));
+ }
+ $output .= View::factory('module/admin/method_detail_foot');
+
+ $output .= '
';
+ $output .= Form::close();
+
+ Block::add(array(
+ 'title'=>_('Update Site Configuration'),
+ 'body'=>$output,
+ ));
+
+ // module_config
+ $output = '';
+ $output .= View::factory($this->viewpath().'/module/head');
+
+ foreach ($o->module_config as $mid => $detail) {
+ $mo = ORM::factory('Module',$mid);
+
+ $output .= View::factory($this->viewpath().'/module/body')
+ ->set('mo',$mo);
+
+ Script::add(array('type'=>'stdin','data'=>'
+ $(document).ready(function() {
+ $("div[id='.$mo->name.']").load("'.URL::link('admin',$mo->name.'/setup',TRUE).'");
+ });'
+ ));
+ }
+
+ $output .= View::factory($this->viewpath().'/module/foot');
+
+ Block::add(array(
+ 'title'=>_('Update Module Specific Configuration'),
+ 'body'=>$output,
+ ));
+ }
+}
+?>
diff --git a/application/classes/Controller/Admin/Welcome.php b/application/classes/Controller/Admin/Welcome.php
new file mode 100644
index 00000000..70da6455
--- /dev/null
+++ b/application/classes/Controller/Admin/Welcome.php
@@ -0,0 +1,130 @@
+TRUE,
+ );
+
+ public function action_index() {
+ $t = time();
+
+ // Show outstanding invoices
+ $o = ORM::factory('Invoice');
+
+ Block_Sub::add(array(
+ 'title'=>'Invoices Overdue - No Auto Billing',
+ 'body'=>Table::display(
+ $o->list_overdue_billing($t),
+ 25,
+ array(
+ 'due_date'=>array('label'=>'Due Date'),
+ 'account->accnum()'=>array('label'=>'Num'),
+ 'account->name()'=>array('label'=>'Account'),
+ 'account->display("status")'=>array('label'=>'Active'),
+ 'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')),
+ 'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
+ 'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
+ ),
+ array('page'=>TRUE)),
+ 'position'=>1,
+ 'order'=>1,
+ ));
+
+ Block_Sub::add(array(
+ 'title'=>'Invoices Overdue - Auto Billing',
+ 'body'=>Table::display(
+ $o->list_overdue_billing($t,TRUE),
+ 25,
+ array(
+ 'due_date'=>array('label'=>'Due Date'),
+ 'account->accnum()'=>array('label'=>'Num'),
+ 'account->name()'=>array('label'=>'Account'),
+ 'account->display("status")'=>array('label'=>'Active'),
+ 'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')),
+ 'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
+ 'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
+ ),
+ array('page'=>TRUE)),
+ 'position'=>2,
+ 'order'=>1,
+ ));
+
+ Block_Sub::add(array(
+ 'title'=>'Invoices Due',
+ 'body'=>Table::display(
+ $o->list_due(),
+ 25,
+ array(
+ 'due_date'=>array('label'=>'Due Date'),
+ 'account->accnum()'=>array('label'=>'Num'),
+ 'account->name()'=>array('label'),
+ 'account->display("status")'=>array('label'=>'Active'),
+ 'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')),
+ 'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
+ 'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
+ ),
+ array('show_other'=>'due()')),
+ 'position'=>3,
+ 'order'=>1,
+ ));
+
+ // Show un-applied payments
+ Block_Sub::add(array(
+ 'title'=>'Unapplied Payments',
+ 'body'=>Table::display(
+ ORM::factory('Payment')->list_unapplied(),
+ 25,
+ array(
+ 'date_payment'=>array('label'=>'Pay Date'),
+ 'account->accnum()'=>array('label'=>'Num'),
+ 'account->name()'=>array('label'=>'Account'),
+ 'account->display("status")'=>array('label'=>'Active'),
+ 'id'=>array('label'=>'ID','url'=>URL::link('admin','payment/view/')),
+ 'total_amt'=>array('label'=>'Total','class'=>'right'),
+ 'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
+ ),
+ array('show_other'=>'balance()')),
+ 'position'=>1,
+ 'order'=>2,
+ ));
+
+ Block::add(array(
+ 'title'=>sprintf('%s: %s %s',$this->ao->accnum(),$this->ao->first_name,$this->ao->last_name),
+ 'subtitle'=>_('Administrator Overview'),
+ 'body'=>(string)Block_Sub::factory(),
+ ));
+
+ // We are a site administrator
+ $output = '';
+ if ($this->ao->rtm_id == NULL) {
+ $rtmo = ORM::factory('RTM',array('account_id','=',$this->ao->id))->find();
+
+ // Quick validation, if we are an admin, we should have an entry in the RTM table.
+ if (! $rtmo->loaded())
+ throw new Kohana_Exception('User :aid not set up properly',array(':aid'=>$this->ao->id));
+
+ $output = View::factory('welcome/admin')
+ ->set('o',$rtmo);
+
+ } else {
+ $rtmo = ORM::factory('RTM',$this->ao->rtm_id);
+ }
+
+ if ($output)
+ Block::add(array(
+ 'title'=>sprintf('Reseller %s',$this->ao->display('company')),
+ 'body'=>$output,
+ ));
+ }
+}
+?>
diff --git a/application/classes/Controller/Debug.php b/application/classes/Controller/Debug.php
new file mode 100644
index 00000000..bf24b47c
--- /dev/null
+++ b/application/classes/Controller/Debug.php
@@ -0,0 +1,36 @@
+__METHOD__,
+ 'site'=>Config::site(),
+ 'siteID'=>Company::instance()->site(),
+ 'siteMode'=>Config::sitemodeverbose(),
+ 'modules'=>Config::appmodules(),
+ ));
+
+ Block::add(array(
+ 'title'=>_('Site debug'),
+ 'body'=>$output,
+ ));
+ }
+}
+?>
diff --git a/application/classes/Controller/Login.php b/application/classes/Controller/Login.php
new file mode 100644
index 00000000..076fb38f
--- /dev/null
+++ b/application/classes/Controller/Login.php
@@ -0,0 +1,92 @@
+logged_in())
+ HTTP::redirect('welcome/index');
+
+ HTTP::redirect('login');
+ }
+
+ /**
+ * Enable user password reset
+ */
+ public function action_reset() {
+ // Minutes to keep our token
+ $token_expire = 15;
+
+ // If user already signed-in
+ if (Auth::instance()->logged_in())
+ HTTP::redirect('welcome/index');
+
+ // If the user posted their details to reset their password
+ if ($_POST) {
+ // If the username is correct, create a method token
+ if (! empty($_POST['username']) AND ($ao=ORM::factory('Account',array('username'=>$_POST['username']))) AND $ao->loaded()) {
+ $mmto = ORM::factory('Module_Method_Token')
+ ->method(array('account','user_resetpassword'))
+ ->account($ao)
+ ->uses(2)
+ ->expire(time()+$token_expire*60);
+
+ if ($mmto->generate()) {
+ // Send our email with the token
+ // @todo Need to provide an option if Email_Template is not installed/activited.
+ // @todo Need to provide an option if account_reset_password template doesnt exist.
+ $et = Email_Template::instance('account_reset_password');
+ $et->to = array('account'=>array($mmto->account_id));
+ $et->variables = array(
+ 'SITE'=>URL::base(TRUE,TRUE),
+ 'SITE_ADMIN'=>Company::instance()->admin(),
+ 'SITE_NAME'=>Company::instance()->name(),
+ 'TOKEN'=>$mmto->token,
+ 'TOKEN_EXPIRE_MIN'=>$token_expire,
+ 'USER_NAME'=>sprintf('%s %s',$mmto->account->first_name,$mmto->account->last_name),
+ );
+ $et->send();
+
+ // Log the password reset
+ $ao->log('Password reset token sent');
+ }
+
+ // Redirect to our password reset, the Auth will validate the token.
+ } elseif (! empty($_REQUEST['token'])) {
+ HTTP::redirect(URL::link('user','account/resetpassword?token='.$_REQUEST['token']));
+ }
+
+ // Show our token screen even if the email was invalid.
+ if (isset($_POST['username']))
+ Block::add(array(
+ 'title'=>_('Reset your password'),
+ 'body'=>View::factory('login_reset_sent'),
+ 'style'=>array('css/login.css'=>'screen'),
+ ));
+ else
+ HTTP::redirect('login');
+
+ } else {
+ Block::add(array(
+ 'title'=>_('Reset your password'),
+ 'body'=>View::factory('login_reset'),
+ 'style'=>array('css/login.css'=>'screen'),
+ ));
+ }
+ }
+}
+?>
diff --git a/application/classes/Controller/Module.php b/application/classes/Controller/Module.php
new file mode 100644
index 00000000..8c4829fa
--- /dev/null
+++ b/application/classes/Controller/Module.php
@@ -0,0 +1,14 @@
+
diff --git a/application/classes/Controller/Reseller/Account.php b/application/classes/Controller/Reseller/Account.php
new file mode 100644
index 00000000..6059075b
--- /dev/null
+++ b/application/classes/Controller/Reseller/Account.php
@@ -0,0 +1,81 @@
+TRUE,
+ 'list'=>TRUE,
+ 'listlog'=>TRUE,
+ );
+
+ /**
+ * Used by AJAX calls to find accounts
+ * @note list_autocomplete() will limit to authorised accounts
+ */
+ public function action_ajaxlist() {
+ $result = array();
+
+ if (isset($_REQUEST['term']) AND trim($_REQUEST['term']))
+ $result += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
+
+ $this->auto_render = FALSE;
+ $this->response->headers('Content-Type','application/json');
+ $this->response->body(json_encode(array_values($result)));
+ }
+
+ /**
+ * Show a list of accounts
+ */
+ public function action_list() {
+ Block::add(array(
+ 'title'=>_('Customer List'),
+ 'body'=>Table::display(
+ $this->filter(ORM::factory('Account')->list_active(),$this->ao->RTM->customers($this->ao->RTM),'sortkey(TRUE)','id'),
+ 25,
+ array(
+ 'id'=>array('label'=>'ID','url'=>URL::link('reseller','invoice/list/')),
+ 'accnum()'=>array('label'=>'Num'),
+ 'name(TRUE)'=>array('label'=>'Account'),
+ 'email'=>array('label'=>'Email'),
+ 'invoices_due_total(NULL,TRUE)'=>array('label'=>'Invoices','class'=>'right'),
+ 'services_count(TRUE)'=>array('label'=>'Services','class'=>'right'),
+ ),
+ array(
+ 'page'=>TRUE,
+ 'type'=>'select',
+ 'form'=>URL::link('reseller','invoice/list'),
+ )),
+ ));
+ }
+
+ /**
+ * Show a list of account logins
+ */
+ public function action_listlog() {
+ Block::add(array(
+ 'title'=>_('Account Login Log'),
+ 'body'=>Table::display(
+ $this->filter(ORM::factory('Account_Log')->find_all(),$this->ao->RTM->customers($this->ao->RTM),NULL,'account_id'),
+ 25,
+ array(
+ 'id'=>array('label'=>'ID'),
+ 'date_orig'=>array('label'=>'Date'),
+ 'account->name()'=>array('label'=>'Account'),
+ 'ip'=>array('label'=>'IP Address'),
+ 'details'=>array('label'=>'Details'),
+ ),
+ array(
+ 'page'=>TRUE,
+ )),
+ ));
+ }
+}
+?>
diff --git a/application/classes/Controller/Reseller/Welcome.php b/application/classes/Controller/Reseller/Welcome.php
new file mode 100644
index 00000000..3194d3ae
--- /dev/null
+++ b/application/classes/Controller/Reseller/Welcome.php
@@ -0,0 +1,25 @@
+TRUE,
+ );
+
+ public function action_index() {
+ Block::add(array(
+ 'title'=>sprintf('%s: %s',$this->ao->accnum(),$this->ao->name(TRUE)),
+ 'body'=>View::factory('welcome/reseller'),
+ ));
+ }
+}
+?>
diff --git a/application/classes/Controller/TemplateDefault.php b/application/classes/Controller/TemplateDefault.php
new file mode 100644
index 00000000..e7ed22d7
--- /dev/null
+++ b/application/classes/Controller/TemplateDefault.php
@@ -0,0 +1,134 @@
+template = Config::theme().'/page';
+
+ return parent::__construct($request,$response);
+ }
+
+ protected function _headimages() {
+ // This is where we should be able to change our country
+ // @todo To implement
+ $co = Config::country();
+ HeadImages::add(array(
+ 'img'=>sprintf('img/country/%s.png',strtolower($co->two_code)),
+ 'attrs'=>array('onclick'=>"target='_blank';",'title'=>$co->display('name'))
+ ));
+
+ return HeadImages::factory();
+ }
+
+ protected function _left() {
+ if ($this->template->left)
+ return $this->template->left;
+
+ elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__))
+ return Controller_Tree::js();
+ }
+
+ protected function _right() {
+ return ($this->template->right) ? $this->template->right : '';
+ }
+
+ public function before() {
+ // If our action doesnt exist, no point processing any further.
+ if (! method_exists($this,'action_'.Request::current()->action()))
+ return;
+
+ if ($this->auth_required) {
+ if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
+ throw new Kohana_Exception('Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
+
+ $this->ao = Auth::instance()->get_user();
+
+ if (! is_null($this->ao) AND (is_string($this->ao) OR ! $this->ao->loaded()))
+ throw HTTP_Exception::factory(501,'Account doesnt exist :account ?',array(':account'=>(is_string($this->ao) OR is_null($this->ao)) ? $this->ao : Auth::instance()->get_user()->id));
+ }
+
+ parent::before();
+ }
+
+ public function after() {
+ $dc = Kohana::$config->load('config','user_default_method');
+ $m = sprintf('%s/%s',Request::current()->directory(),Request::current()->controller());
+
+ BreadCrumb::URL(Request::current()->directory(),sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
+ BreadCrumb::URL($m,method_exists($this,'action_menu') ? $m.'/menu' : sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
+
+ parent::after();
+ }
+
+ /**
+ * This will filter a search query to only return those accounts for a reseller
+ */
+ protected function filter($o,$af,$sort=NULL,$afid=NULL) {
+ $result = array();
+
+ foreach ($o as $x) {
+ if (! is_null($afid) AND isset($x->$afid)) {
+ if ((is_array($af) AND in_array($x->$afid,$af)) OR ($x->$afid == $af))
+ array_push($result,$x);
+
+ } elseif (method_exists($x,'list_reseller')) {
+ if (in_array($af,$x->list_reseller()))
+ array_push($result,$x);
+
+ }
+ }
+
+ if ($sort)
+ Sort::MAsort($result,$sort);
+
+ return $result;
+ }
+
+ protected function setup(array $config_items=array()) {
+ $module = Request::current()->controller();
+
+ if ($_POST AND isset($_POST['module_config'][$module]))
+ Config::instance()->module_config($module,$_POST['module_config'][$module])->save();
+
+ if ($config_items) {
+ $output = '';
+ $mc = Config::instance()->module_config($module);
+
+ $output .= Form::open();
+ $output .= View::factory('setup/admin/module/head');
+
+ foreach ($config_items as $k=>$v)
+ $output .= View::factory('setup/admin/module/body')
+ ->set('module',$module)
+ ->set('mc',$mc)
+ ->set('key',$k)
+ ->set('info',$v)
+ ->set('val',isset($mc[$k]) ? $mc[$k] : '');
+
+ $output .= View::factory('setup/admin/module/foot');
+
+ $output .= Form::submit('submit',_('Submit'),array('class'=>'form_button'));
+ $output .= Form::close();
+
+ Block::add(array(
+ 'title'=>sprintf('%s: %s',strtoupper($module),_('Configuration')),
+ 'body'=>$output,
+ ));
+ }
+ }
+}
+?>
diff --git a/application/classes/Controller/TemplateDefault/Admin.php b/application/classes/Controller/TemplateDefault/Admin.php
new file mode 100644
index 00000000..3bbcb4d4
--- /dev/null
+++ b/application/classes/Controller/TemplateDefault/Admin.php
@@ -0,0 +1,23 @@
+'Retire this class extension',
+ 'type'=>'info',
+ 'body'=>__METHOD__,
+ ));
+
+ return parent::after();
+ }
+}
+?>
diff --git a/application/classes/Controller/TemplateDefault/Affiliate.php b/application/classes/Controller/TemplateDefault/Affiliate.php
new file mode 100644
index 00000000..d95e4ad8
--- /dev/null
+++ b/application/classes/Controller/TemplateDefault/Affiliate.php
@@ -0,0 +1,23 @@
+'Retire this class extension',
+ 'type'=>'info',
+ 'body'=>__METHOD__,
+ ));
+
+ return parent::after();
+ }
+}
+?>
diff --git a/application/classes/Controller/TemplateDefault/User.php b/application/classes/Controller/TemplateDefault/User.php
new file mode 100644
index 00000000..3983d57d
--- /dev/null
+++ b/application/classes/Controller/TemplateDefault/User.php
@@ -0,0 +1,14 @@
+
diff --git a/application/classes/Controller/Tree.php b/application/classes/Controller/Tree.php
new file mode 100644
index 00000000..f6e27a8b
--- /dev/null
+++ b/application/classes/Controller/Tree.php
@@ -0,0 +1,131 @@
+request->param('id')) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $this->request->param('id');
+ $user = Auth::instance()->get_user();
+
+ if ($user) {
+ if (! $id) {
+ $modules = array();
+ foreach ($user->groups() as $go)
+ foreach ($go->list_parentgrps(TRUE) as $cgo)
+ foreach ($cgo->module_method->find_all() as $mmo)
+ if ($mmo->menu_display AND empty($modules[$mmo->module_id]))
+ $modules[$mmo->module_id] = $mmo->module;
+
+ Sort::MAsort($modules,'name');
+
+ foreach ($modules as $id => $mo)
+ if (! $mo->parent_id)
+ array_push($data,array('id'=>$id,'name'=>$mo->name,'state'=>'closed'));
+
+ } else {
+ $idx = NULL;
+ if (preg_match('/_/',$id))
+ list($id,$idx) = explode('_',$id,2);
+
+ $mo = ORM::factory('Module',$id);
+
+ $methods = array();
+ if ($mo->loaded()) {
+ foreach ($mo->module_method->find_all() as $mmo)
+ if ($mmo->menu_display)
+ foreach ($mmo->group->find_all() as $gmo)
+ if ($user->has_any('group',$gmo->list_childgrps(TRUE)))
+ $methods[$mmo->id] = $mmo;
+
+ Sort::MASort($modules,'name');
+
+ $subdata = array();
+ foreach ($methods as $id => $mmo) {
+ if (preg_match('/_/',$mmo->name)) {
+ list($mode,$action) = explode('_',$mmo->name);
+
+ $url = URL::link($mode,$mmo->module->name.'/'.$action,TRUE);
+
+ } else {
+ $url = URL::site($mmo->module->name.'/'.$mmo->name);
+ }
+
+ // We can split our menus into sub menus using the _ char.
+ if (preg_match('/_/',$mmo->name)) {
+ list($sub,$name) = explode('_',$mmo->name,2);
+ $subdata[$sub][$name]['name'] = preg_replace('/^(.*: )/','',$mmo->notes);
+ $subdata[$sub][$name]['id'] = sprintf('%s_%s',$mmo->module_id,$id);
+ $subdata[$sub][$name]['href'] = (empty($details['page']) ? $url : $details['page']);
+
+ } else {
+ // We dont want to show these items again, if we can through on a submenu
+ if (! $idx)
+ array_push($data,array(
+ 'id'=>sprintf('%s_%s',$mmo->module_id,$id),
+ 'name'=>$mmo->name,
+ 'state'=>'none',
+ 'attr_id'=>sprintf('%s_%s',$mmo->module->name,$id),
+ 'attr_href'=>(empty($details['page']) ? $url : $details['page'])
+ ));
+ }
+ }
+
+ // If our sub menus only have 1 branch, then we'll display it as normal.
+ if (count($subdata) == 1) {
+ $sk = array_keys($subdata);
+ $idx = array_shift($sk);
+ }
+
+ if ($idx)
+ foreach ($subdata[$idx] as $k=>$v) {
+ array_push($data,array(
+ 'id'=>$v['id'],
+ 'name'=>$v['name'],
+ 'state'=>'none',
+ 'attr_id'=>$v['id'],
+ 'attr_href'=>$v['href']
+ ));
+ }
+
+ else
+ foreach ($subdata as $t=>$x)
+ array_push($data,array('id'=>$mmo->module_id.'_'.$t,'name'=>$t,'state'=>'closed'));
+
+ }
+ }
+ }
+
+ $this->output = array();
+
+ foreach ($data as $branch) {
+ array_push($this->output,array(
+ 'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
+ 'state'=>$branch['state'],
+ 'data'=>array('title'=>$branch['name']),
+ 'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('%s/menu',$branch['name'])) : $branch['attr_href']),
+ )
+ );
+ }
+
+ return parent::action_json($data);
+ }
+}
+?>
diff --git a/application/classes/Controller/User/Account.php b/application/classes/Controller/User/Account.php
new file mode 100644
index 00000000..49075694
--- /dev/null
+++ b/application/classes/Controller/User/Account.php
@@ -0,0 +1,104 @@
+TRUE,
+ 'resetpassword'=>TRUE,
+ );
+
+ /**
+ * Enable User to Edit their Account Details
+ */
+ public function action_edit() {
+ // Store our new values
+ $this->ao->values($_POST);
+
+ // Run validation and save
+ if ($this->ao->changed())
+ if ($this->ao->check()) {
+ SystemMessage::add(array(
+ 'title'=>_('Record updated'),
+ 'type'=>'info',
+ 'body'=>_('Your account record has been updated.')
+ ));
+
+ $this->ao->save();
+
+ } else {
+ $output = '';
+ foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
+ $output .= sprintf('
%s %s
',$field,$error);
+
+ if ($output)
+ $output = sprintf('
%s
',$output);
+
+ SystemMessage::add(array(
+ 'title'=>_('Record NOT updated'),
+ 'type'=>'error',
+ 'body'=>_('Your updates didnt pass validation.').' '.$output,
+ ));
+ }
+
+ Block::add(array(
+ 'title'=>sprintf('%s: %s - %s',_('Account Edit'),$this->ao->accnum(),$this->ao->name(TRUE)),
+ 'body'=>View::factory($this->viewpath())
+ ->set('record',$this->ao),
+ ));
+ }
+
+ public function action_resetpassword() {
+ // @todo Fix this next logic, since matches_ifset is not being called when the value is on the form, but empty
+ if (empty($_POST['password_confirm']))
+ $_POST['password_confirm'] = ' ';
+
+ // Store our new values
+ $this->ao->values($_POST);
+
+ // Run validation and save
+ if ($this->ao->changed())
+ if ($this->ao->check()) {
+ SystemMessage::add(array(
+ 'title'=>_('Record updated'),
+ 'type'=>'info',
+ 'body'=>_('Your account record has been updated.')
+ ));
+
+ $this->ao->save();
+
+ // Log the password reset
+ $this->ao->log('Password reset');
+
+ HTTP::redirect('login');
+
+ } else {
+ $output = '';
+ foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
+ $output .= sprintf('
%s %s
',$field,$error);
+
+ if ($output)
+ $output = sprintf('
*/
+ background: #cde;
+ padding: 2px 2px 0px 2px;
+}
+
+.calendar tbody td.selected { /* Cell showing today date */
+ font-weight: bold;
+ border: 1px solid #000;
+ padding: 1px 3px 1px 1px;
+ background: #fff;
+ color: #000;
+}
+
+.calendar tbody td.weekend { /* Cells showing weekend days */
+ color: #a66;
+}
+
+.calendar tbody td.today { /* Cell showing selected date */
+ font-weight: bold;
+ color: #00f;
+}
+
+.calendar tbody .disabled { color: #999; }
+
+.calendar tbody .emptycell { /* Empty cells (the best is to hide them) */
+ visibility: hidden;
+}
+
+.calendar tbody .emptyrow { /* Empty row (some months need less than 6 rows) */
+ display: none;
+}
+
+/* The footer part -- status bar and "Close" button */
+
+.calendar tfoot .footrow { /* The
in footer (only one right now) */
+ text-align: center;
+ background: #556;
+ color: #fff;
+}
+
+.calendar tfoot .ttip { /* Tooltip (status bar) cell
*/
+ background: #fff;
+ color: #445;
+ border-top: 1px solid #556;
+ padding: 1px;
+}
+
+.calendar tfoot .hilite { /* Hover style for buttons in footer */
+ background: #aaf;
+ border: 1px solid #04f;
+ color: #000;
+ padding: 1px;
+}
+
+.calendar tfoot .active { /* Active (pressed) style for buttons in footer */
+ background: #77c;
+ padding: 2px 0px 0px 2px;
+}
+
+/* Combo boxes (menus that display months/years for direct selection) */
+
+.calendar .combo {
+ position: absolute;
+ display: none;
+ top: 0px;
+ left: 0px;
+ width: 4em;
+ cursor: default;
+ border: 1px solid #655;
+ background: #def;
+ color: #000;
+ font-size: 90%;
+ z-index: 100;
+}
+
+.calendar .combo .label,
+.calendar .combo .label-IEfix {
+ text-align: center;
+ padding: 1px;
+}
+
+.calendar .combo .label-IEfix {
+ width: 4em;
+}
+
+.calendar .combo .hilite {
+ background: #acf;
+}
+
+.calendar .combo .active {
+ border-top: 1px solid #46a;
+ border-bottom: 1px solid #46a;
+ background: #eef;
+ font-weight: bold;
+}
+
+.calendar td.time {
+ border-top: 1px solid #000;
+ padding: 1px 0px;
+ text-align: center;
+ background-color: #f4f0e8;
+}
+
+.calendar td.time .hour,
+.calendar td.time .minute,
+.calendar td.time .ampm {
+ padding: 0px 3px 0px 4px;
+ border: 1px solid #889;
+ font-weight: bold;
+ background-color: #fff;
+}
+
+.calendar td.time .ampm {
+ text-align: center;
+}
+
+.calendar td.time .colon {
+ padding: 0px 2px 0px 3px;
+ font-weight: bold;
+}
+
+.calendar td.time span.hilite {
+ border-color: #000;
+ background-color: #667;
+ color: #fff;
+}
+
+.calendar td.time span.active {
+ border-color: #f00;
+ background-color: #000;
+ color: #0f0;
+}
diff --git a/application/media/css/dhtml.menuarrow.gif b/application/media/css/dhtml.menuarrow.gif
new file mode 100644
index 00000000..ed2dee0e
Binary files /dev/null and b/application/media/css/dhtml.menuarrow.gif differ
diff --git a/application/media/css/html5reset-1.6.1.css b/application/media/css/html5reset-1.6.1.css
new file mode 100644
index 00000000..39cf8f00
--- /dev/null
+++ b/application/media/css/html5reset-1.6.1.css
@@ -0,0 +1,102 @@
+/*
+html5doctor.com Reset Stylesheet
+v1.6.1
+Last Updated: 2010-09-17
+Author: Richard Clark - http://richclarkdesign.com
+Twitter: @rich_clark
+*/
+
+html, body, div, span, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+abbr, address, cite, code,
+del, dfn, em, img, ins, kbd, q, samp,
+small, strong, sub, sup, var,
+b, i,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+article, aside, canvas, details, figcaption, figure,
+footer, header, hgroup, menu, nav, section, summary,
+time, mark, audio, video {
+ margin:0;
+ padding:0;
+ border:0;
+ outline:0;
+ font-size:100%;
+ vertical-align:baseline;
+ background:transparent;
+}
+
+body {
+ line-height:1;
+}
+
+article,aside,details,figcaption,figure,
+footer,header,hgroup,menu,nav,section {
+ display:block;
+}
+
+nav ul {
+ list-style:none;
+}
+
+blockquote, q {
+ quotes:none;
+}
+
+blockquote:before, blockquote:after,
+q:before, q:after {
+ content:'';
+ content:none;
+}
+
+a {
+ margin:0;
+ padding:0;
+ font-size:100%;
+ vertical-align:baseline;
+ background:transparent;
+}
+
+/* change colours to suit your needs */
+ins {
+ background-color:#ff9;
+ color:#000;
+ text-decoration:none;
+}
+
+/* change colours to suit your needs */
+mark {
+ background-color:#ff9;
+ color:#000;
+ font-style:italic;
+ font-weight:bold;
+}
+
+del {
+ text-decoration: line-through;
+}
+
+abbr[title], dfn[title] {
+ border-bottom:1px dotted;
+ cursor:help;
+}
+
+table {
+ border-collapse:collapse;
+ border-spacing:0;
+}
+
+/* change border colour to suit your needs */
+hr {
+ display:block;
+ height:1px;
+ border:0;
+ border-top:1px solid #cccccc;
+ margin:1em 0;
+ padding:0;
+}
+
+input, select {
+ vertical-align:middle;
+}
\ No newline at end of file
diff --git a/application/media/css/jquery.gritter.css b/application/media/css/jquery.gritter.css
new file mode 100644
index 00000000..0d6cba50
--- /dev/null
+++ b/application/media/css/jquery.gritter.css
@@ -0,0 +1,92 @@
+/* ie6 trash */
+* html #gritter-notice-wrapper {
+ position:absolute;
+}
+* html .gritter-top {
+ margin-bottom:-10px;
+}
+* html .gritter-item {
+ padding-bottom:0;
+}
+* html .gritter-bottom {
+ margin-bottom:0;
+}
+* html .gritter-close {
+ background:url(../img/jquery.gritter-close-ie6.gif);
+ width:22px;
+ height:22px;
+ top:7px;
+ left:7px;
+}
+
+/* the norm */
+#gritter-notice-wrapper {
+ position:fixed;
+ top:20px;
+ right:20px;
+ width:301px;
+ z-index:9999;
+}
+.gritter-item-wrapper {
+ position:relative;
+ margin:0 0 10px 0;
+}
+.gritter-top {
+ background:url(../img/jquery.gritter.png) no-repeat left -30px;
+ height:10px;
+}
+.hover .gritter-top {
+ background-position:right -30px;
+}
+.gritter-bottom {
+ background:url(../img/jquery.gritter.png) no-repeat left bottom;
+ height:8px;
+ margin:0;
+}
+.hover .gritter-bottom {
+ background-position: bottom right;
+}
+.gritter-item {
+ display:block;
+ background:url(../img/jquery.gritter.png) no-repeat left -40px;
+ color:#eee;
+ padding:2px 11px 8px 11px;
+ font-size: 11px;
+ font-family:verdana;
+}
+.hover .gritter-item {
+ background-position:right -40px;
+}
+.gritter-item p {
+ padding:0;
+ margin:0;
+}
+.gritter-close {
+ position:absolute;
+ top:5px;
+ left:3px;
+ background:url(../img/jquery.gritter.png) no-repeat left top;
+ cursor:pointer;
+ width:30px;
+ height:30px;
+}
+.gritter-title {
+ font-size:14px;
+ font-weight:bold;
+ padding:0 0 7px 0;
+ display:block;
+ text-shadow:1px 1px #000; /* Not supported by IE :( */
+}
+.gritter-image {
+ width:24px;
+ height:24px;
+ float:left;
+}
+.gritter-with-image,
+.gritter-without-image {
+ padding:0 0 0px 0;
+}
+.gritter-with-image {
+ width:250px;
+ float:right;
+}
diff --git a/application/media/css/login.css b/application/media/css/login.css
new file mode 100644
index 00000000..cecbce68
--- /dev/null
+++ b/application/media/css/login.css
@@ -0,0 +1,44 @@
+/** Login Style Sheet **/
+
+table.login {
+ width: 5%;
+ margin-left: auto;
+ margin-right: auto;
+ background-color: #FBFBFB;
+ border: 1px solid #A0A0A0;
+ padding: 10px;
+}
+
+#login-uid {
+ background: url('../img/login.user.png') no-repeat 0 1px;
+ background-color: #FAFAFF;
+ color: #000000;
+ padding-left: 24px;
+}
+
+#login-uid:focus {
+ background-color: #F0F0FF;
+ color: #000000;
+}
+
+#login-uid:disabled {
+ background-color: #DDDDFF;
+ color: #000000;
+}
+
+#login-pwd {
+ background: url('../img/dialog-password.png') no-repeat 0 1px;
+ background-color: #FAFAFF;
+ color: #000000;
+ padding-left: 24px;
+}
+
+#login-pwd:focus {
+ background-color: #F0F0FF;
+ color: #000000;
+}
+
+#login-pwd:disabled {
+ background-color: #DDDDFF;
+ color: #000000;
+}
diff --git a/application/media/img/address-book-new-big.png b/application/media/img/address-book-new-big.png
new file mode 100644
index 00000000..aa7c4e01
Binary files /dev/null and b/application/media/img/address-book-new-big.png differ
diff --git a/application/media/img/address-book-new.png b/application/media/img/address-book-new.png
new file mode 100644
index 00000000..e37385cc
Binary files /dev/null and b/application/media/img/address-book-new.png differ
diff --git a/application/media/img/ajax-progress.gif b/application/media/img/ajax-progress.gif
new file mode 100644
index 00000000..994bfab6
Binary files /dev/null and b/application/media/img/ajax-progress.gif differ
diff --git a/application/media/img/bug-big.png b/application/media/img/bug-big.png
new file mode 100644
index 00000000..0758a855
Binary files /dev/null and b/application/media/img/bug-big.png differ
diff --git a/application/media/img/calendar.png b/application/media/img/calendar.png
new file mode 100644
index 00000000..c3cdf73c
Binary files /dev/null and b/application/media/img/calendar.png differ
diff --git a/application/media/img/country/au.png b/application/media/img/country/au.png
new file mode 100644
index 00000000..b20b0480
Binary files /dev/null and b/application/media/img/country/au.png differ
diff --git a/application/media/img/dialog-error-big.png b/application/media/img/dialog-error-big.png
new file mode 100644
index 00000000..49ed5303
Binary files /dev/null and b/application/media/img/dialog-error-big.png differ
diff --git a/application/media/img/dialog-error.png b/application/media/img/dialog-error.png
new file mode 100644
index 00000000..f8050129
Binary files /dev/null and b/application/media/img/dialog-error.png differ
diff --git a/application/media/img/dialog-information-big.png b/application/media/img/dialog-information-big.png
new file mode 100644
index 00000000..cca5804c
Binary files /dev/null and b/application/media/img/dialog-information-big.png differ
diff --git a/application/media/img/dialog-information.png b/application/media/img/dialog-information.png
new file mode 100644
index 00000000..00accf1c
Binary files /dev/null and b/application/media/img/dialog-information.png differ
diff --git a/application/media/img/dialog-password-big.png b/application/media/img/dialog-password-big.png
new file mode 100644
index 00000000..e40a48d8
Binary files /dev/null and b/application/media/img/dialog-password-big.png differ
diff --git a/application/media/img/dialog-password.png b/application/media/img/dialog-password.png
new file mode 100644
index 00000000..eb8dd242
Binary files /dev/null and b/application/media/img/dialog-password.png differ
diff --git a/application/media/img/dialog-question-big.png b/application/media/img/dialog-question-big.png
new file mode 100644
index 00000000..2361f74d
Binary files /dev/null and b/application/media/img/dialog-question-big.png differ
diff --git a/application/media/img/dialog-question.png b/application/media/img/dialog-question.png
new file mode 100644
index 00000000..ec077614
Binary files /dev/null and b/application/media/img/dialog-question.png differ
diff --git a/application/media/img/dialog-warning-big.png b/application/media/img/dialog-warning-big.png
new file mode 100644
index 00000000..a9ff09b3
Binary files /dev/null and b/application/media/img/dialog-warning-big.png differ
diff --git a/application/media/img/dialog-warning.png b/application/media/img/dialog-warning.png
new file mode 100644
index 00000000..63b08f9a
Binary files /dev/null and b/application/media/img/dialog-warning.png differ
diff --git a/application/media/img/forum-big.png b/application/media/img/forum-big.png
new file mode 100644
index 00000000..bbda895a
Binary files /dev/null and b/application/media/img/forum-big.png differ
diff --git a/application/media/img/gnome-pdf.png b/application/media/img/gnome-pdf.png
new file mode 100644
index 00000000..f2c8b21f
Binary files /dev/null and b/application/media/img/gnome-pdf.png differ
diff --git a/application/media/img/gritter-close-ie6.gif b/application/media/img/gritter-close-ie6.gif
new file mode 100644
index 00000000..aea6e427
Binary files /dev/null and b/application/media/img/gritter-close-ie6.gif differ
diff --git a/application/media/img/gritter.png b/application/media/img/gritter.png
new file mode 100755
index 00000000..0ca3bc0a
Binary files /dev/null and b/application/media/img/gritter.png differ
diff --git a/application/media/img/help-about-big.png b/application/media/img/help-about-big.png
new file mode 100644
index 00000000..45b5d620
Binary files /dev/null and b/application/media/img/help-about-big.png differ
diff --git a/application/media/img/help-about.png b/application/media/img/help-about.png
new file mode 100644
index 00000000..435ea0ee
Binary files /dev/null and b/application/media/img/help-about.png differ
diff --git a/application/media/img/help-big.png b/application/media/img/help-big.png
new file mode 100644
index 00000000..bbda895a
Binary files /dev/null and b/application/media/img/help-big.png differ
diff --git a/application/media/img/help-faq-big.png b/application/media/img/help-faq-big.png
new file mode 100644
index 00000000..1d57544f
Binary files /dev/null and b/application/media/img/help-faq-big.png differ
diff --git a/application/media/img/help-faq.png b/application/media/img/help-faq.png
new file mode 100644
index 00000000..69e0ce1e
Binary files /dev/null and b/application/media/img/help-faq.png differ
diff --git a/application/media/img/help.png b/application/media/img/help.png
new file mode 100644
index 00000000..674a8e92
Binary files /dev/null and b/application/media/img/help.png differ
diff --git a/application/media/img/jquery.gritter.close-ie6.gif b/application/media/img/jquery.gritter.close-ie6.gif
new file mode 100644
index 00000000..aea6e427
Binary files /dev/null and b/application/media/img/jquery.gritter.close-ie6.gif differ
diff --git a/application/media/img/jquery.gritter.png b/application/media/img/jquery.gritter.png
new file mode 100644
index 00000000..0ca3bc0a
Binary files /dev/null and b/application/media/img/jquery.gritter.png differ
diff --git a/application/media/img/jquery.jstree.d.png b/application/media/img/jquery.jstree.d.png
new file mode 100644
index 00000000..8540175a
Binary files /dev/null and b/application/media/img/jquery.jstree.d.png differ
diff --git a/application/media/img/jquery.jstree.throbber.gif b/application/media/img/jquery.jstree.throbber.gif
new file mode 100644
index 00000000..5b33f7e5
Binary files /dev/null and b/application/media/img/jquery.jstree.throbber.gif differ
diff --git a/application/media/img/login.user.png b/application/media/img/login.user.png
new file mode 100644
index 00000000..7be48fb8
Binary files /dev/null and b/application/media/img/login.user.png differ
diff --git a/application/media/img/logo-small.png b/application/media/img/logo-small.png
new file mode 100644
index 00000000..726933b1
Binary files /dev/null and b/application/media/img/logo-small.png differ
diff --git a/application/media/img/logo.png b/application/media/img/logo.png
new file mode 100644
index 00000000..1cb15547
Binary files /dev/null and b/application/media/img/logo.png differ
diff --git a/application/media/img/request-feature-big.png b/application/media/img/request-feature-big.png
new file mode 100644
index 00000000..b7b12414
Binary files /dev/null and b/application/media/img/request-feature-big.png differ
diff --git a/application/media/img/smile-big.png b/application/media/img/smile-big.png
new file mode 100644
index 00000000..22fba5ff
Binary files /dev/null and b/application/media/img/smile-big.png differ
diff --git a/application/media/img/toggle-closed.png b/application/media/img/toggle-closed.png
new file mode 100644
index 00000000..f66b1a80
Binary files /dev/null and b/application/media/img/toggle-closed.png differ
diff --git a/application/media/img/toggle-open.png b/application/media/img/toggle-open.png
new file mode 100644
index 00000000..6ff90668
Binary files /dev/null and b/application/media/img/toggle-open.png differ
diff --git a/application/media/img/ui-anim_basic_16x16.gif b/application/media/img/ui-anim_basic_16x16.gif
new file mode 100644
index 00000000..084ecb87
Binary files /dev/null and b/application/media/img/ui-anim_basic_16x16.gif differ
diff --git a/application/media/js/dhtml.calendar-en.js b/application/media/js/dhtml.calendar-en.js
new file mode 100644
index 00000000..1736202e
--- /dev/null
+++ b/application/media/js/dhtml.calendar-en.js
@@ -0,0 +1,9 @@
+/*
+ * Calendar EN language
+ * Author: Mihai Bazon,
+ */
+Calendar._DN=new Array
+("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");Calendar._SDN=new Array
+("Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun");Calendar._FD=0;Calendar._MN=new Array
+("January","February","March","April","May","June","July","August","September","October","November","December");Calendar._SMN=new Array
+("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");Calendar._TT={};Calendar._TT["INFO"]="About the calendar";Calendar._TT["ABOUT"]="DHTML Date/Time Selector\n"+"(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n"+"For latest version visit: http://www.dynarch.com/projects/calendar/\n"+"Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details."+"\n\n"+"Date selection:\n"+"- Use the \xab, \xbb buttons to select year\n"+"- Use the "+String.fromCharCode(0x2039)+", "+String.fromCharCode(0x203a)+" buttons to select month\n"+"- Hold mouse button on any of the above buttons for faster selection.";Calendar._TT["ABOUT_TIME"]="\n\n"+"Time selection:\n"+"- Click on any of the time parts to increase it\n"+"- or Shift-click to decrease it\n"+"- or click and drag for faster selection.";Calendar._TT["PREV_YEAR"]="Prev. year (hold for menu)";Calendar._TT["PREV_MONTH"]="Prev. month (hold for menu)";Calendar._TT["GO_TODAY"]="Go Today";Calendar._TT["NEXT_MONTH"]="Next month (hold for menu)";Calendar._TT["NEXT_YEAR"]="Next year (hold for menu)";Calendar._TT["SEL_DATE"]="Select date";Calendar._TT["DRAG_TO_MOVE"]="Drag to move";Calendar._TT["PART_TODAY"]=" (today)";Calendar._TT["DAY_FIRST"]="Display %s first";Calendar._TT["WEEKEND"]="0,6";Calendar._TT["CLOSE"]="Close";Calendar._TT["TODAY"]="Today";Calendar._TT["TIME_PART"]="(Shift-)Click or drag to change value";Calendar._TT["DEF_DATE_FORMAT"]="%Y-%m-%d";Calendar._TT["TT_DATE_FORMAT"]="%a, %b %e";Calendar._TT["WK"]="wk";Calendar._TT["TIME"]="Time:";
diff --git a/application/media/js/dhtml.calendar-setup.js b/application/media/js/dhtml.calendar-setup.js
new file mode 100644
index 00000000..c269f7dd
--- /dev/null
+++ b/application/media/js/dhtml.calendar-setup.js
@@ -0,0 +1,200 @@
+/* Copyright Mihai Bazon, 2002, 2003 | http://dynarch.com/mishoo/
+ * ---------------------------------------------------------------------------
+ *
+ * The DHTML Calendar
+ *
+ * Details and latest version at:
+ * http://dynarch.com/mishoo/calendar.epl
+ *
+ * This script is distributed under the GNU Lesser General Public License.
+ * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
+ *
+ * This file defines helper functions for setting up the calendar. They are
+ * intended to help non-programmers get a working calendar on their site
+ * quickly. This script should not be seen as part of the calendar. It just
+ * shows you what one can do with the calendar, while in the same time
+ * providing a quick and simple method for setting it up. If you need
+ * exhaustive customization of the calendar creation process feel free to
+ * modify this code to suit your needs (this is recommended and much better
+ * than modifying calendar.js itself).
+ */
+
+// $Id$
+
+/**
+ * This function "patches" an input field (or other element) to use a calendar
+ * widget for date selection.
+ *
+ * The "params" is a single object that can have the following properties:
+ *
+ * prop. name | description
+ * -------------------------------------------------------------------------------------------------
+ * inputField | the ID of an input field to store the date
+ * displayArea | the ID of a DIV or other element to show the date
+ * button | ID of a button or other element that will trigger the calendar
+ * eventName | event that will trigger the calendar, without the "on" prefix (default: "click")
+ * ifFormat | date format that will be stored in the input field
+ * daFormat | the date format that will be used to display the date in displayArea
+ * singleClick | (true/false) wether the calendar is in single click mode or not (default: true)
+ * firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc.
+ * align | alignment (default: "Br"); if you don't know what's this see the calendar documentation
+ * range | array with 2 elements. Default: [1900, 2999] -- the range of years available
+ * weekNumbers | (true/false) if it's true (default) the calendar will display week numbers
+ * flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
+ * flatCallback | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar)
+ * disableFunc | function that receives a JS Date object and should return true if that date has to be disabled in the calendar
+ * onSelect | function that gets called when a date is selected. You don't _have_ to supply this (the default is generally okay)
+ * onClose | function that gets called when the calendar is closed. [default]
+ * onUpdate | function that gets called after the date is updated in the input field. Receives a reference to the calendar.
+ * date | the date that the calendar will be initially displayed to
+ * showsTime | default: false; if true the calendar will include a time selector
+ * timeFormat | the time format; can be "12" or "24", default is "12"
+ * electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
+ * step | configures the step of the years in drop-down boxes; default: 2
+ * position | configures the calendar absolute position; default: null
+ * cache | if "true" (but default: "false") it will reuse the same calendar object, where possible
+ * showOthers | if "true" (but default: "false") it will show days from other months too
+ *
+ * None of them is required, they all have default values. However, if you
+ * pass none of "inputField", "displayArea" or "button" you'll get a warning
+ * saying "nothing to setup".
+ */
+Calendar.setup = function (params) {
+ function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };
+
+ param_default("inputField", null);
+ param_default("displayArea", null);
+ param_default("button", null);
+ param_default("eventName", "click");
+ param_default("ifFormat", "%Y/%m/%d");
+ param_default("daFormat", "%Y/%m/%d");
+ param_default("singleClick", true);
+ param_default("disableFunc", null);
+ param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined
+ param_default("dateText", null);
+ param_default("firstDay", null);
+ param_default("align", "Br");
+ param_default("range", [1900, 2999]);
+ param_default("weekNumbers", true);
+ param_default("flat", null);
+ param_default("flatCallback", null);
+ param_default("onSelect", null);
+ param_default("onClose", null);
+ param_default("onUpdate", null);
+ param_default("date", null);
+ param_default("showsTime", false);
+ param_default("timeFormat", "24");
+ param_default("electric", true);
+ param_default("step", 2);
+ param_default("position", null);
+ param_default("cache", false);
+ param_default("showOthers", false);
+ param_default("multiple", null);
+
+ var tmp = ["inputField", "displayArea", "button"];
+ for (var i in tmp) {
+ if (typeof params[tmp[i]] == "string") {
+ params[tmp[i]] = document.getElementById(params[tmp[i]]);
+ }
+ }
+ if (!(params.flat || params.multiple || params.inputField || params.displayArea || params.button)) {
+ alert("Calendar.setup:\n Nothing to setup (no fields found). Please check your code");
+ return false;
+ }
+
+ function onSelect(cal) {
+ var p = cal.params;
+ var update = (cal.dateClicked || p.electric);
+ if (update && p.inputField) {
+ p.inputField.value = cal.date.print(p.ifFormat);
+ if (typeof p.inputField.onchange == "function")
+ p.inputField.onchange();
+ }
+ if (update && p.displayArea)
+ p.displayArea.innerHTML = cal.date.print(p.daFormat);
+ if (update && typeof p.onUpdate == "function")
+ p.onUpdate(cal);
+ if (update && p.flat) {
+ if (typeof p.flatCallback == "function")
+ p.flatCallback(cal);
+ }
+ if (update && p.singleClick && cal.dateClicked)
+ cal.callCloseHandler();
+ };
+
+ if (params.flat != null) {
+ if (typeof params.flat == "string")
+ params.flat = document.getElementById(params.flat);
+ if (!params.flat) {
+ alert("Calendar.setup:\n Flat specified but can't find parent.");
+ return false;
+ }
+ var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect);
+ cal.showsOtherMonths = params.showOthers;
+ cal.showsTime = params.showsTime;
+ cal.time24 = (params.timeFormat == "24");
+ cal.params = params;
+ cal.weekNumbers = params.weekNumbers;
+ cal.setRange(params.range[0], params.range[1]);
+ cal.setDateStatusHandler(params.dateStatusFunc);
+ cal.getDateText = params.dateText;
+ if (params.ifFormat) {
+ cal.setDateFormat(params.ifFormat);
+ }
+ if (params.inputField && typeof params.inputField.value == "string") {
+ cal.parseDate(params.inputField.value);
+ }
+ cal.create(params.flat);
+ cal.show();
+ return false;
+ }
+
+ var triggerEl = params.button || params.displayArea || params.inputField;
+ triggerEl["on" + params.eventName] = function() {
+ var dateEl = params.inputField || params.displayArea;
+ var dateFmt = params.inputField ? params.ifFormat : params.daFormat;
+ var mustCreate = false;
+ var cal = window.calendar;
+ if (dateEl)
+ params.date = Date.parseDate(dateEl.value || dateEl.innerHTML, dateFmt);
+ if (!(cal && params.cache)) {
+ window.calendar = cal = new Calendar(params.firstDay,
+ params.date,
+ params.onSelect || onSelect,
+ params.onClose || function(cal) { cal.hide(); });
+ cal.showsTime = params.showsTime;
+ cal.time24 = (params.timeFormat == "24");
+ cal.weekNumbers = params.weekNumbers;
+ mustCreate = true;
+ } else {
+ if (params.date)
+ cal.setDate(params.date);
+ cal.hide();
+ }
+ if (params.multiple) {
+ cal.multiple = {};
+ for (var i = params.multiple.length; --i >= 0;) {
+ var d = params.multiple[i];
+ var ds = d.print("%Y%m%d");
+ cal.multiple[ds] = d;
+ }
+ }
+ cal.showsOtherMonths = params.showOthers;
+ cal.yearStep = params.step;
+ cal.setRange(params.range[0], params.range[1]);
+ cal.params = params;
+ cal.setDateStatusHandler(params.dateStatusFunc);
+ cal.getDateText = params.dateText;
+ cal.setDateFormat(dateFmt);
+ if (mustCreate)
+ cal.create();
+ cal.refresh();
+ if (!params.position)
+ cal.showAtElement(params.button || params.displayArea || params.inputField, params.align);
+ else
+ cal.showAt(params.position[0], params.position[1]);
+ return false;
+ };
+
+ return cal;
+};
diff --git a/application/media/js/dhtml.calendar.js b/application/media/js/dhtml.calendar.js
new file mode 100644
index 00000000..f6c13981
--- /dev/null
+++ b/application/media/js/dhtml.calendar.js
@@ -0,0 +1,1806 @@
+/* Copyright Mihai Bazon, 2002-2005 | www.bazon.net/mishoo
+ * -----------------------------------------------------------
+ *
+ * The DHTML Calendar, version 1.0 "It is happening again"
+ *
+ * Details and latest version at:
+ * www.dynarch.com/projects/calendar
+ *
+ * This script is developed by Dynarch.com. Visit us at www.dynarch.com.
+ *
+ * This script is distributed under the GNU Lesser General Public License.
+ * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
+ */
+
+// $Id$
+
+/** The Calendar object constructor. */
+Calendar = function (firstDayOfWeek, dateStr, onSelected, onClose) {
+ // member variables
+ this.activeDiv = null;
+ this.currentDateEl = null;
+ this.getDateStatus = null;
+ this.getDateToolTip = null;
+ this.getDateText = null;
+ this.timeout = null;
+ this.onSelected = onSelected || null;
+ this.onClose = onClose || null;
+ this.dragging = false;
+ this.hidden = false;
+ this.minYear = 1970;
+ this.maxYear = 2050;
+ this.dateFormat = Calendar._TT["DEF_DATE_FORMAT"];
+ this.ttDateFormat = Calendar._TT["TT_DATE_FORMAT"];
+ this.isPopup = true;
+ this.weekNumbers = true;
+ this.firstDayOfWeek = typeof firstDayOfWeek == "number" ? firstDayOfWeek : Calendar._FD; // 0 for Sunday, 1 for Monday, etc.
+ this.showsOtherMonths = false;
+ this.dateStr = dateStr;
+ this.ar_days = null;
+ this.showsTime = false;
+ this.time24 = true;
+ this.yearStep = 2;
+ this.hiliteToday = true;
+ this.multiple = null;
+ // HTML elements
+ this.table = null;
+ this.element = null;
+ this.tbody = null;
+ this.firstdayname = null;
+ // Combo boxes
+ this.monthsCombo = null;
+ this.yearsCombo = null;
+ this.hilitedMonth = null;
+ this.activeMonth = null;
+ this.hilitedYear = null;
+ this.activeYear = null;
+ // Information
+ this.dateClicked = false;
+
+ // one-time initializations
+ if (typeof Calendar._SDN == "undefined") {
+ // table of short day names
+ if (typeof Calendar._SDN_len == "undefined")
+ Calendar._SDN_len = 3;
+ var ar = new Array();
+ for (var i = 8; i > 0;) {
+ ar[--i] = Calendar._DN[i].substr(0, Calendar._SDN_len);
+ }
+ Calendar._SDN = ar;
+ // table of short month names
+ if (typeof Calendar._SMN_len == "undefined")
+ Calendar._SMN_len = 3;
+ ar = new Array();
+ for (var i = 12; i > 0;) {
+ ar[--i] = Calendar._MN[i].substr(0, Calendar._SMN_len);
+ }
+ Calendar._SMN = ar;
+ }
+};
+
+// ** constants
+
+/// "static", needed for event handlers.
+Calendar._C = null;
+
+/// detect a special case of "web browser"
+Calendar.is_ie = ( /msie/i.test(navigator.userAgent) &&
+ !/opera/i.test(navigator.userAgent) );
+
+Calendar.is_ie5 = ( Calendar.is_ie && /msie 5\.0/i.test(navigator.userAgent) );
+
+/// detect Opera browser
+Calendar.is_opera = /opera/i.test(navigator.userAgent);
+
+/// detect KHTML-based browsers
+Calendar.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
+
+// BEGIN: UTILITY FUNCTIONS; beware that these might be moved into a separate
+// library, at some point.
+
+Calendar.getAbsolutePos = function(el) {
+ var SL = 0, ST = 0;
+ var is_div = /^div$/i.test(el.tagName);
+ if (is_div && el.scrollLeft)
+ SL = el.scrollLeft;
+ if (is_div && el.scrollTop)
+ ST = el.scrollTop;
+ var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
+ if (el.offsetParent) {
+ var tmp = this.getAbsolutePos(el.offsetParent);
+ r.x += tmp.x;
+ r.y += tmp.y;
+ }
+ return r;
+};
+
+Calendar.isRelated = function (el, evt) {
+ var related = evt.relatedTarget;
+ if (!related) {
+ var type = evt.type;
+ if (type == "mouseover") {
+ related = evt.fromElement;
+ } else if (type == "mouseout") {
+ related = evt.toElement;
+ }
+ }
+ while (related) {
+ if (related == el) {
+ return true;
+ }
+ related = related.parentNode;
+ }
+ return false;
+};
+
+Calendar.removeClass = function(el, className) {
+ if (!(el && el.className)) {
+ return;
+ }
+ var cls = el.className.split(" ");
+ var ar = new Array();
+ for (var i = cls.length; i > 0;) {
+ if (cls[--i] != className) {
+ ar[ar.length] = cls[i];
+ }
+ }
+ el.className = ar.join(" ");
+};
+
+Calendar.addClass = function(el, className) {
+ Calendar.removeClass(el, className);
+ el.className += " " + className;
+};
+
+// FIXME: the following 2 functions totally suck, are useless and should be replaced immediately.
+Calendar.getElement = function(ev) {
+ var f = Calendar.is_ie ? window.event.srcElement : ev.currentTarget;
+ while (f.nodeType != 1 || /^div$/i.test(f.tagName))
+ f = f.parentNode;
+ return f;
+};
+
+Calendar.getTargetElement = function(ev) {
+ var f = Calendar.is_ie ? window.event.srcElement : ev.target;
+ while (f.nodeType != 1)
+ f = f.parentNode;
+ return f;
+};
+
+Calendar.stopEvent = function(ev) {
+ ev || (ev = window.event);
+ if (Calendar.is_ie) {
+ ev.cancelBubble = true;
+ ev.returnValue = false;
+ } else {
+ ev.preventDefault();
+ ev.stopPropagation();
+ }
+ return false;
+};
+
+Calendar.addEvent = function(el, evname, func) {
+ if (el.attachEvent) { // IE
+ el.attachEvent("on" + evname, func);
+ } else if (el.addEventListener) { // Gecko / W3C
+ el.addEventListener(evname, func, true);
+ } else {
+ el["on" + evname] = func;
+ }
+};
+
+Calendar.removeEvent = function(el, evname, func) {
+ if (el.detachEvent) { // IE
+ el.detachEvent("on" + evname, func);
+ } else if (el.removeEventListener) { // Gecko / W3C
+ el.removeEventListener(evname, func, true);
+ } else {
+ el["on" + evname] = null;
+ }
+};
+
+Calendar.createElement = function(type, parent) {
+ var el = null;
+ if (document.createElementNS) {
+ // use the XHTML namespace; IE won't normally get here unless
+ // _they_ "fix" the DOM2 implementation.
+ el = document.createElementNS("http://www.w3.org/1999/xhtml", type);
+ } else {
+ el = document.createElement(type);
+ }
+ if (typeof parent != "undefined") {
+ parent.appendChild(el);
+ }
+ return el;
+};
+
+// END: UTILITY FUNCTIONS
+
+// BEGIN: CALENDAR STATIC FUNCTIONS
+
+/** Internal -- adds a set of events to make some element behave like a button. */
+Calendar._add_evs = function(el) {
+ with (Calendar) {
+ addEvent(el, "mouseover", dayMouseOver);
+ addEvent(el, "mousedown", dayMouseDown);
+ addEvent(el, "mouseout", dayMouseOut);
+ if (is_ie) {
+ addEvent(el, "dblclick", dayMouseDblClick);
+ el.setAttribute("unselectable", true);
+ }
+ }
+};
+
+Calendar.findMonth = function(el) {
+ if (typeof el.month != "undefined") {
+ return el;
+ } else if (typeof el.parentNode.month != "undefined") {
+ return el.parentNode;
+ }
+ return null;
+};
+
+Calendar.findYear = function(el) {
+ if (typeof el.year != "undefined") {
+ return el;
+ } else if (typeof el.parentNode.year != "undefined") {
+ return el.parentNode;
+ }
+ return null;
+};
+
+Calendar.showMonthsCombo = function () {
+ var cal = Calendar._C;
+ if (!cal) {
+ return false;
+ }
+ var cal = cal;
+ var cd = cal.activeDiv;
+ var mc = cal.monthsCombo;
+ if (cal.hilitedMonth) {
+ Calendar.removeClass(cal.hilitedMonth, "hilite");
+ }
+ if (cal.activeMonth) {
+ Calendar.removeClass(cal.activeMonth, "active");
+ }
+ var mon = cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()];
+ Calendar.addClass(mon, "active");
+ cal.activeMonth = mon;
+ var s = mc.style;
+ s.display = "block";
+ if (cd.navtype < 0)
+ s.left = cd.offsetLeft + "px";
+ else {
+ var mcw = mc.offsetWidth;
+ if (typeof mcw == "undefined")
+ // Konqueror brain-dead techniques
+ mcw = 50;
+ s.left = (cd.offsetLeft + cd.offsetWidth - mcw) + "px";
+ }
+ s.top = (cd.offsetTop + cd.offsetHeight) + "px";
+};
+
+Calendar.showYearsCombo = function (fwd) {
+ var cal = Calendar._C;
+ if (!cal) {
+ return false;
+ }
+ var cal = cal;
+ var cd = cal.activeDiv;
+ var yc = cal.yearsCombo;
+ if (cal.hilitedYear) {
+ Calendar.removeClass(cal.hilitedYear, "hilite");
+ }
+ if (cal.activeYear) {
+ Calendar.removeClass(cal.activeYear, "active");
+ }
+ cal.activeYear = null;
+ var Y = cal.date.getFullYear() + (fwd ? 1 : -1);
+ var yr = yc.firstChild;
+ var show = false;
+ for (var i = 12; i > 0; --i) {
+ if (Y >= cal.minYear && Y <= cal.maxYear) {
+ yr.innerHTML = Y;
+ yr.year = Y;
+ yr.style.display = "block";
+ show = true;
+ } else {
+ yr.style.display = "none";
+ }
+ yr = yr.nextSibling;
+ Y += fwd ? cal.yearStep : -cal.yearStep;
+ }
+ if (show) {
+ var s = yc.style;
+ s.display = "block";
+ if (cd.navtype < 0)
+ s.left = cd.offsetLeft + "px";
+ else {
+ var ycw = yc.offsetWidth;
+ if (typeof ycw == "undefined")
+ // Konqueror brain-dead techniques
+ ycw = 50;
+ s.left = (cd.offsetLeft + cd.offsetWidth - ycw) + "px";
+ }
+ s.top = (cd.offsetTop + cd.offsetHeight) + "px";
+ }
+};
+
+// event handlers
+
+Calendar.tableMouseUp = function(ev) {
+ var cal = Calendar._C;
+ if (!cal) {
+ return false;
+ }
+ if (cal.timeout) {
+ clearTimeout(cal.timeout);
+ }
+ var el = cal.activeDiv;
+ if (!el) {
+ return false;
+ }
+ var target = Calendar.getTargetElement(ev);
+ ev || (ev = window.event);
+ Calendar.removeClass(el, "active");
+ if (target == el || target.parentNode == el) {
+ Calendar.cellClick(el, ev);
+ }
+ var mon = Calendar.findMonth(target);
+ var date = null;
+ if (mon) {
+ date = new Date(cal.date);
+ if (mon.month != date.getMonth()) {
+ date.setMonth(mon.month);
+ cal.setDate(date);
+ cal.dateClicked = false;
+ cal.callHandler();
+ }
+ } else {
+ var year = Calendar.findYear(target);
+ if (year) {
+ date = new Date(cal.date);
+ if (year.year != date.getFullYear()) {
+ date.setFullYear(year.year);
+ cal.setDate(date);
+ cal.dateClicked = false;
+ cal.callHandler();
+ }
+ }
+ }
+ with (Calendar) {
+ removeEvent(document, "mouseup", tableMouseUp);
+ removeEvent(document, "mouseover", tableMouseOver);
+ removeEvent(document, "mousemove", tableMouseOver);
+ cal._hideCombos();
+ _C = null;
+ return stopEvent(ev);
+ }
+};
+
+Calendar.tableMouseOver = function (ev) {
+ var cal = Calendar._C;
+ if (!cal) {
+ return;
+ }
+ var el = cal.activeDiv;
+ var target = Calendar.getTargetElement(ev);
+ if (target == el || target.parentNode == el) {
+ Calendar.addClass(el, "hilite active");
+ Calendar.addClass(el.parentNode, "rowhilite");
+ } else {
+ if (typeof el.navtype == "undefined" || (el.navtype != 50 && (el.navtype == 0 || Math.abs(el.navtype) > 2)))
+ Calendar.removeClass(el, "active");
+ Calendar.removeClass(el, "hilite");
+ Calendar.removeClass(el.parentNode, "rowhilite");
+ }
+ ev || (ev = window.event);
+ if (el.navtype == 50 && target != el) {
+ var pos = Calendar.getAbsolutePos(el);
+ var w = el.offsetWidth;
+ var x = ev.clientX;
+ var dx;
+ var decrease = true;
+ if (x > pos.x + w) {
+ dx = x - pos.x - w;
+ decrease = false;
+ } else
+ dx = pos.x - x;
+
+ if (dx < 0) dx = 0;
+ var range = el._range;
+ var current = el._current;
+ var count = Math.floor(dx / 10) % range.length;
+ for (var i = range.length; --i >= 0;)
+ if (range[i] == current)
+ break;
+ while (count-- > 0)
+ if (decrease) {
+ if (--i < 0)
+ i = range.length - 1;
+ } else if ( ++i >= range.length )
+ i = 0;
+ var newval = range[i];
+ el.innerHTML = newval;
+
+ cal.onUpdateTime();
+ }
+ var mon = Calendar.findMonth(target);
+ if (mon) {
+ if (mon.month != cal.date.getMonth()) {
+ if (cal.hilitedMonth) {
+ Calendar.removeClass(cal.hilitedMonth, "hilite");
+ }
+ Calendar.addClass(mon, "hilite");
+ cal.hilitedMonth = mon;
+ } else if (cal.hilitedMonth) {
+ Calendar.removeClass(cal.hilitedMonth, "hilite");
+ }
+ } else {
+ if (cal.hilitedMonth) {
+ Calendar.removeClass(cal.hilitedMonth, "hilite");
+ }
+ var year = Calendar.findYear(target);
+ if (year) {
+ if (year.year != cal.date.getFullYear()) {
+ if (cal.hilitedYear) {
+ Calendar.removeClass(cal.hilitedYear, "hilite");
+ }
+ Calendar.addClass(year, "hilite");
+ cal.hilitedYear = year;
+ } else if (cal.hilitedYear) {
+ Calendar.removeClass(cal.hilitedYear, "hilite");
+ }
+ } else if (cal.hilitedYear) {
+ Calendar.removeClass(cal.hilitedYear, "hilite");
+ }
+ }
+ return Calendar.stopEvent(ev);
+};
+
+Calendar.tableMouseDown = function (ev) {
+ if (Calendar.getTargetElement(ev) == Calendar.getElement(ev)) {
+ return Calendar.stopEvent(ev);
+ }
+};
+
+Calendar.calDragIt = function (ev) {
+ var cal = Calendar._C;
+ if (!(cal && cal.dragging)) {
+ return false;
+ }
+ var posX;
+ var posY;
+ if (Calendar.is_ie) {
+ posY = window.event.clientY + document.body.scrollTop;
+ posX = window.event.clientX + document.body.scrollLeft;
+ } else {
+ posX = ev.pageX;
+ posY = ev.pageY;
+ }
+ cal.hideShowCovered();
+ var st = cal.element.style;
+ st.left = (posX - cal.xOffs) + "px";
+ st.top = (posY - cal.yOffs) + "px";
+ return Calendar.stopEvent(ev);
+};
+
+Calendar.calDragEnd = function (ev) {
+ var cal = Calendar._C;
+ if (!cal) {
+ return false;
+ }
+ cal.dragging = false;
+ with (Calendar) {
+ removeEvent(document, "mousemove", calDragIt);
+ removeEvent(document, "mouseup", calDragEnd);
+ tableMouseUp(ev);
+ }
+ cal.hideShowCovered();
+};
+
+Calendar.dayMouseDown = function(ev) {
+ var el = Calendar.getElement(ev);
+ if (el.disabled) {
+ return false;
+ }
+ var cal = el.calendar;
+ cal.activeDiv = el;
+ Calendar._C = cal;
+ if (el.navtype != 300) with (Calendar) {
+ if (el.navtype == 50) {
+ el._current = el.innerHTML;
+ addEvent(document, "mousemove", tableMouseOver);
+ } else
+ addEvent(document, Calendar.is_ie5 ? "mousemove" : "mouseover", tableMouseOver);
+ addClass(el, "hilite active");
+ addEvent(document, "mouseup", tableMouseUp);
+ } else if (cal.isPopup) {
+ cal._dragStart(ev);
+ }
+ if (el.navtype == -1 || el.navtype == 1) {
+ if (cal.timeout) clearTimeout(cal.timeout);
+ cal.timeout = setTimeout("Calendar.showMonthsCombo()", 250);
+ } else if (el.navtype == -2 || el.navtype == 2) {
+ if (cal.timeout) clearTimeout(cal.timeout);
+ cal.timeout = setTimeout((el.navtype > 0) ? "Calendar.showYearsCombo(true)" : "Calendar.showYearsCombo(false)", 250);
+ } else {
+ cal.timeout = null;
+ }
+ return Calendar.stopEvent(ev);
+};
+
+Calendar.dayMouseDblClick = function(ev) {
+ Calendar.cellClick(Calendar.getElement(ev), ev || window.event);
+ if (Calendar.is_ie) {
+ document.selection.empty();
+ }
+};
+
+Calendar.dayMouseOver = function(ev) {
+ var el = Calendar.getElement(ev);
+ if (Calendar.isRelated(el, ev) || Calendar._C || el.disabled) {
+ return false;
+ }
+ if (el.ttip) {
+ if (el.ttip.substr(0, 1) == "_") {
+ el.ttip = el.caldate.print(el.calendar.ttDateFormat) + el.ttip.substr(1);
+ }
+ el.calendar.tooltips.innerHTML = el.ttip;
+ }
+ if (el.navtype != 300) {
+ Calendar.addClass(el, "hilite");
+ if (el.caldate) {
+ Calendar.addClass(el.parentNode, "rowhilite");
+ }
+ }
+ return Calendar.stopEvent(ev);
+};
+
+Calendar.dayMouseOut = function(ev) {
+ with (Calendar) {
+ var el = getElement(ev);
+ if (isRelated(el, ev) || _C || el.disabled)
+ return false;
+ removeClass(el, "hilite");
+ if (el.caldate)
+ removeClass(el.parentNode, "rowhilite");
+ if (el.calendar)
+ el.calendar.tooltips.innerHTML = _TT["SEL_DATE"];
+ return stopEvent(ev);
+ }
+};
+
+/**
+ * A generic "click" handler :) handles all types of buttons defined in this
+ * calendar.
+ */
+Calendar.cellClick = function(el, ev) {
+ var cal = el.calendar;
+ var closing = false;
+ var newdate = false;
+ var date = null;
+ if (typeof el.navtype == "undefined") {
+ if (cal.currentDateEl) {
+ Calendar.removeClass(cal.currentDateEl, "selected");
+ Calendar.addClass(el, "selected");
+ closing = (cal.currentDateEl == el);
+ if (!closing) {
+ cal.currentDateEl = el;
+ }
+ }
+ cal.date.setDateOnly(el.caldate);
+ date = cal.date;
+ var other_month = !(cal.dateClicked = !el.otherMonth);
+ if (!other_month && !cal.currentDateEl)
+ cal._toggleMultipleDate(new Date(date));
+ else
+ newdate = !el.disabled;
+ // a date was clicked
+ if (other_month)
+ cal._init(cal.firstDayOfWeek, date);
+ } else {
+ if (el.navtype == 200) {
+ Calendar.removeClass(el, "hilite");
+ cal.callCloseHandler();
+ return;
+ }
+ date = new Date(cal.date);
+ if (el.navtype == 0)
+ date.setDateOnly(new Date()); // TODAY
+ // unless "today" was clicked, we assume no date was clicked so
+ // the selected handler will know not to close the calenar when
+ // in single-click mode.
+ // cal.dateClicked = (el.navtype == 0);
+ cal.dateClicked = false;
+ var year = date.getFullYear();
+ var mon = date.getMonth();
+ function setMonth(m) {
+ var day = date.getDate();
+ var max = date.getMonthDays(m);
+ if (day > max) {
+ date.setDate(max);
+ }
+ date.setMonth(m);
+ };
+ switch (el.navtype) {
+ case 400:
+ Calendar.removeClass(el, "hilite");
+ var text = Calendar._TT["ABOUT"];
+ if (typeof text != "undefined") {
+ text += cal.showsTime ? Calendar._TT["ABOUT_TIME"] : "";
+ } else {
+ // FIXME: this should be removed as soon as lang files get updated!
+ text = "Help and about box text is not translated into this language.\n" +
+ "If you know this language and you feel generous please update\n" +
+ "the corresponding file in \"lang\" subdir to match calendar-en.js\n" +
+ "and send it back to to get it into the distribution ;-)\n\n" +
+ "Thank you!\n" +
+ "http://dynarch.com/mishoo/calendar.epl\n";
+ }
+ alert(text);
+ return;
+ case -2:
+ if (year > cal.minYear) {
+ date.setFullYear(year - 1);
+ }
+ break;
+ case -1:
+ if (mon > 0) {
+ setMonth(mon - 1);
+ } else if (year-- > cal.minYear) {
+ date.setFullYear(year);
+ setMonth(11);
+ }
+ break;
+ case 1:
+ if (mon < 11) {
+ setMonth(mon + 1);
+ } else if (year < cal.maxYear) {
+ date.setFullYear(year + 1);
+ setMonth(0);
+ }
+ break;
+ case 2:
+ if (year < cal.maxYear) {
+ date.setFullYear(year + 1);
+ }
+ break;
+ case 100:
+ cal.setFirstDayOfWeek(el.fdow);
+ return;
+ case 50:
+ var range = el._range;
+ var current = el.innerHTML;
+ for (var i = range.length; --i >= 0;)
+ if (range[i] == current)
+ break;
+ if (ev && ev.shiftKey) {
+ if (--i < 0)
+ i = range.length - 1;
+ } else if ( ++i >= range.length )
+ i = 0;
+ var newval = range[i];
+ el.innerHTML = newval;
+ cal.onUpdateTime();
+ return;
+ case 0:
+ // TODAY will bring us here
+ if ((typeof cal.getDateStatus == "function") &&
+ cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate())) {
+ return false;
+ }
+ break;
+ }
+ if (!date.equalsTo(cal.date)) {
+ cal.setDate(date);
+ newdate = true;
+ } else if (el.navtype == 0)
+ newdate = closing = true;
+ }
+ if (newdate) {
+ ev && cal.callHandler();
+ }
+ if (closing) {
+ Calendar.removeClass(el, "hilite");
+ ev && cal.callCloseHandler();
+ }
+};
+
+// END: CALENDAR STATIC FUNCTIONS
+
+// BEGIN: CALENDAR OBJECT FUNCTIONS
+
+/**
+ * This function creates the calendar inside the given parent. If _par is
+ * null than it creates a popup calendar inside the BODY element. If _par is
+ * an element, be it BODY, then it creates a non-popup calendar (still
+ * hidden). Some properties need to be set before calling this function.
+ */
+Calendar.prototype.create = function (_par) {
+ var parent = null;
+ if (! _par) {
+ // default parent is the document body, in which case we create
+ // a popup calendar.
+ parent = document.getElementsByTagName("body")[0];
+ this.isPopup = true;
+ } else {
+ parent = _par;
+ this.isPopup = false;
+ }
+ this.date = this.dateStr ? new Date(this.dateStr) : new Date();
+
+ var table = Calendar.createElement("table");
+ this.table = table;
+ table.cellSpacing = 0;
+ table.cellPadding = 0;
+ table.calendar = this;
+ Calendar.addEvent(table, "mousedown", Calendar.tableMouseDown);
+
+ var div = Calendar.createElement("div");
+ this.element = div;
+ div.className = "calendar";
+ if (this.isPopup) {
+ div.style.position = "absolute";
+ div.style.display = "none";
+ }
+ div.appendChild(table);
+
+ var thead = Calendar.createElement("thead", table);
+ var cell = null;
+ var row = null;
+
+ var cal = this;
+ var hh = function (text, cs, navtype) {
+ cell = Calendar.createElement("td", row);
+ cell.colSpan = cs;
+ cell.className = "button";
+ if (navtype != 0 && Math.abs(navtype) <= 2)
+ cell.className += " nav";
+ Calendar._add_evs(cell);
+ cell.calendar = cal;
+ cell.navtype = navtype;
+ cell.innerHTML = "
" + text + "
";
+ return cell;
+ };
+
+ row = Calendar.createElement("tr", thead);
+ var title_length = 6;
+ (this.isPopup) && --title_length;
+ (this.weekNumbers) && ++title_length;
+
+ hh("?", 1, 400).ttip = Calendar._TT["INFO"];
+ this.title = hh("", title_length, 300);
+ this.title.className = "title";
+ if (this.isPopup) {
+ this.title.ttip = Calendar._TT["DRAG_TO_MOVE"];
+ this.title.style.cursor = "move";
+ hh("×", 1, 200).ttip = Calendar._TT["CLOSE"];
+ }
+
+ row = Calendar.createElement("tr", thead);
+ row.className = "headrow";
+
+ this._nav_py = hh("«", 1, -2);
+ this._nav_py.ttip = Calendar._TT["PREV_YEAR"];
+
+ this._nav_pm = hh("‹", 1, -1);
+ this._nav_pm.ttip = Calendar._TT["PREV_MONTH"];
+
+ this._nav_now = hh(Calendar._TT["TODAY"], this.weekNumbers ? 4 : 3, 0);
+ this._nav_now.ttip = Calendar._TT["GO_TODAY"];
+
+ this._nav_nm = hh("›", 1, 1);
+ this._nav_nm.ttip = Calendar._TT["NEXT_MONTH"];
+
+ this._nav_ny = hh("»", 1, 2);
+ this._nav_ny.ttip = Calendar._TT["NEXT_YEAR"];
+
+ // day names
+ row = Calendar.createElement("tr", thead);
+ row.className = "daynames";
+ if (this.weekNumbers) {
+ cell = Calendar.createElement("td", row);
+ cell.className = "name wn";
+ cell.innerHTML = Calendar._TT["WK"];
+ }
+ for (var i = 7; i > 0; --i) {
+ cell = Calendar.createElement("td", row);
+ if (!i) {
+ cell.navtype = 100;
+ cell.calendar = this;
+ Calendar._add_evs(cell);
+ }
+ }
+ this.firstdayname = (this.weekNumbers) ? row.firstChild.nextSibling : row.firstChild;
+ this._displayWeekdays();
+
+ var tbody = Calendar.createElement("tbody", table);
+ this.tbody = tbody;
+
+ for (i = 6; i > 0; --i) {
+ row = Calendar.createElement("tr", tbody);
+ if (this.weekNumbers) {
+ cell = Calendar.createElement("td", row);
+ }
+ for (var j = 7; j > 0; --j) {
+ cell = Calendar.createElement("td", row);
+ cell.calendar = this;
+ Calendar._add_evs(cell);
+ }
+ }
+
+ if (this.showsTime) {
+ row = Calendar.createElement("tr", tbody);
+ row.className = "time";
+
+ cell = Calendar.createElement("td", row);
+ cell.className = "time";
+ cell.colSpan = 2;
+ cell.innerHTML = Calendar._TT["TIME"] || " ";
+
+ cell = Calendar.createElement("td", row);
+ cell.className = "time";
+ cell.colSpan = this.weekNumbers ? 4 : 3;
+
+ (function(){
+ function makeTimePart(className, init, range_start, range_end) {
+ var part = Calendar.createElement("span", cell);
+ part.className = className;
+ part.innerHTML = init;
+ part.calendar = cal;
+ part.ttip = Calendar._TT["TIME_PART"];
+ part.navtype = 50;
+ part._range = [];
+ if (typeof range_start != "number")
+ part._range = range_start;
+ else {
+ for (var i = range_start; i <= range_end; ++i) {
+ var txt;
+ if (i < 10 && range_end >= 10) txt = '0' + i;
+ else txt = '' + i;
+ part._range[part._range.length] = txt;
+ }
+ }
+ Calendar._add_evs(part);
+ return part;
+ };
+ var hrs = cal.date.getHours();
+ var mins = cal.date.getMinutes();
+ var t12 = !cal.time24;
+ var pm = (hrs > 12);
+ if (t12 && pm) hrs -= 12;
+ var H = makeTimePart("hour", hrs, t12 ? 1 : 0, t12 ? 12 : 23);
+ var span = Calendar.createElement("span", cell);
+ span.innerHTML = ":";
+ span.className = "colon";
+ var M = makeTimePart("minute", mins, 0, 59);
+ var AP = null;
+ cell = Calendar.createElement("td", row);
+ cell.className = "time";
+ cell.colSpan = 2;
+ if (t12)
+ AP = makeTimePart("ampm", pm ? "pm" : "am", ["am", "pm"]);
+ else
+ cell.innerHTML = " ";
+
+ cal.onSetTime = function() {
+ var pm, hrs = this.date.getHours(),
+ mins = this.date.getMinutes();
+ if (t12) {
+ pm = (hrs >= 12);
+ if (pm) hrs -= 12;
+ if (hrs == 0) hrs = 12;
+ AP.innerHTML = pm ? "pm" : "am";
+ }
+ H.innerHTML = (hrs < 10) ? ("0" + hrs) : hrs;
+ M.innerHTML = (mins < 10) ? ("0" + mins) : mins;
+ };
+
+ cal.onUpdateTime = function() {
+ var date = this.date;
+ var h = parseInt(H.innerHTML, 10);
+ if (t12) {
+ if (/pm/i.test(AP.innerHTML) && h < 12)
+ h += 12;
+ else if (/am/i.test(AP.innerHTML) && h == 12)
+ h = 0;
+ }
+ var d = date.getDate();
+ var m = date.getMonth();
+ var y = date.getFullYear();
+ date.setHours(h);
+ date.setMinutes(parseInt(M.innerHTML, 10));
+ date.setFullYear(y);
+ date.setMonth(m);
+ date.setDate(d);
+ this.dateClicked = false;
+ this.callHandler();
+ };
+ })();
+ } else {
+ this.onSetTime = this.onUpdateTime = function() {};
+ }
+
+ var tfoot = Calendar.createElement("tfoot", table);
+
+ row = Calendar.createElement("tr", tfoot);
+ row.className = "footrow";
+
+ cell = hh(Calendar._TT["SEL_DATE"], this.weekNumbers ? 8 : 7, 300);
+ cell.className = "ttip";
+ if (this.isPopup) {
+ cell.ttip = Calendar._TT["DRAG_TO_MOVE"];
+ cell.style.cursor = "move";
+ }
+ this.tooltips = cell;
+
+ div = Calendar.createElement("div", this.element);
+ this.monthsCombo = div;
+ div.className = "combo";
+ for (i = 0; i < Calendar._MN.length; ++i) {
+ var mn = Calendar.createElement("div");
+ mn.className = Calendar.is_ie ? "label-IEfix" : "label";
+ mn.month = i;
+ mn.innerHTML = Calendar._SMN[i];
+ div.appendChild(mn);
+ }
+
+ div = Calendar.createElement("div", this.element);
+ this.yearsCombo = div;
+ div.className = "combo";
+ for (i = 12; i > 0; --i) {
+ var yr = Calendar.createElement("div");
+ yr.className = Calendar.is_ie ? "label-IEfix" : "label";
+ div.appendChild(yr);
+ }
+
+ this._init(this.firstDayOfWeek, this.date);
+ parent.appendChild(this.element);
+};
+
+/** keyboard navigation, only for popup calendars */
+Calendar._keyEvent = function(ev) {
+ var cal = window._dynarch_popupCalendar;
+ if (!cal || cal.multiple)
+ return false;
+ (Calendar.is_ie) && (ev = window.event);
+ var act = (Calendar.is_ie || ev.type == "keypress"),
+ K = ev.keyCode;
+ if (ev.ctrlKey) {
+ switch (K) {
+ case 37: // KEY left
+ act && Calendar.cellClick(cal._nav_pm);
+ break;
+ case 38: // KEY up
+ act && Calendar.cellClick(cal._nav_py);
+ break;
+ case 39: // KEY right
+ act && Calendar.cellClick(cal._nav_nm);
+ break;
+ case 40: // KEY down
+ act && Calendar.cellClick(cal._nav_ny);
+ break;
+ default:
+ return false;
+ }
+ } else switch (K) {
+ case 32: // KEY space (now)
+ Calendar.cellClick(cal._nav_now);
+ break;
+ case 27: // KEY esc
+ act && cal.callCloseHandler();
+ break;
+ case 37: // KEY left
+ case 38: // KEY up
+ case 39: // KEY right
+ case 40: // KEY down
+ if (act) {
+ var prev, x, y, ne, el, step;
+ prev = K == 37 || K == 38;
+ step = (K == 37 || K == 39) ? 1 : 7;
+ function setVars() {
+ el = cal.currentDateEl;
+ var p = el.pos;
+ x = p & 15;
+ y = p >> 4;
+ ne = cal.ar_days[y][x];
+ };setVars();
+ function prevMonth() {
+ var date = new Date(cal.date);
+ date.setDate(date.getDate() - step);
+ cal.setDate(date);
+ };
+ function nextMonth() {
+ var date = new Date(cal.date);
+ date.setDate(date.getDate() + step);
+ cal.setDate(date);
+ };
+ while (1) {
+ switch (K) {
+ case 37: // KEY left
+ if (--x >= 0)
+ ne = cal.ar_days[y][x];
+ else {
+ x = 6;
+ K = 38;
+ continue;
+ }
+ break;
+ case 38: // KEY up
+ if (--y >= 0)
+ ne = cal.ar_days[y][x];
+ else {
+ prevMonth();
+ setVars();
+ }
+ break;
+ case 39: // KEY right
+ if (++x < 7)
+ ne = cal.ar_days[y][x];
+ else {
+ x = 0;
+ K = 40;
+ continue;
+ }
+ break;
+ case 40: // KEY down
+ if (++y < cal.ar_days.length)
+ ne = cal.ar_days[y][x];
+ else {
+ nextMonth();
+ setVars();
+ }
+ break;
+ }
+ break;
+ }
+ if (ne) {
+ if (!ne.disabled)
+ Calendar.cellClick(ne);
+ else if (prev)
+ prevMonth();
+ else
+ nextMonth();
+ }
+ }
+ break;
+ case 13: // KEY enter
+ if (act)
+ Calendar.cellClick(cal.currentDateEl, ev);
+ break;
+ default:
+ return false;
+ }
+ return Calendar.stopEvent(ev);
+};
+
+/**
+ * (RE)Initializes the calendar to the given date and firstDayOfWeek
+ */
+Calendar.prototype._init = function (firstDayOfWeek, date) {
+ var today = new Date(),
+ TY = today.getFullYear(),
+ TM = today.getMonth(),
+ TD = today.getDate();
+ this.table.style.visibility = "hidden";
+ var year = date.getFullYear();
+ if (year < this.minYear) {
+ year = this.minYear;
+ date.setFullYear(year);
+ } else if (year > this.maxYear) {
+ year = this.maxYear;
+ date.setFullYear(year);
+ }
+ this.firstDayOfWeek = firstDayOfWeek;
+ this.date = new Date(date);
+ var month = date.getMonth();
+ var mday = date.getDate();
+ var no_days = date.getMonthDays();
+
+ // calendar voodoo for computing the first day that would actually be
+ // displayed in the calendar, even if it's from the previous month.
+ // WARNING: this is magic. ;-)
+ date.setDate(1);
+ var day1 = (date.getDay() - this.firstDayOfWeek) % 7;
+ if (day1 < 0)
+ day1 += 7;
+ date.setDate(-day1);
+ date.setDate(date.getDate() + 1);
+
+ var row = this.tbody.firstChild;
+ var MN = Calendar._SMN[month];
+ var ar_days = this.ar_days = new Array();
+ var weekend = Calendar._TT["WEEKEND"];
+ var dates = this.multiple ? (this.datesCells = {}) : null;
+ for (var i = 0; i < 6; ++i, row = row.nextSibling) {
+ var cell = row.firstChild;
+ if (this.weekNumbers) {
+ cell.className = "day wn";
+ cell.innerHTML = date.getWeekNumber();
+ cell = cell.nextSibling;
+ }
+ row.className = "daysrow";
+ var hasdays = false, iday, dpos = ar_days[i] = [];
+ for (var j = 0; j < 7; ++j, cell = cell.nextSibling, date.setDate(iday + 1)) {
+ iday = date.getDate();
+ var wday = date.getDay();
+ cell.className = "day";
+ cell.pos = i << 4 | j;
+ dpos[j] = cell;
+ var current_month = (date.getMonth() == month);
+ if (!current_month) {
+ if (this.showsOtherMonths) {
+ cell.className += " othermonth";
+ cell.otherMonth = true;
+ } else {
+ cell.className = "emptycell";
+ cell.innerHTML = " ";
+ cell.disabled = true;
+ continue;
+ }
+ } else {
+ cell.otherMonth = false;
+ hasdays = true;
+ }
+ cell.disabled = false;
+ cell.innerHTML = this.getDateText ? this.getDateText(date, iday) : iday;
+ if (dates)
+ dates[date.print("%Y%m%d")] = cell;
+ if (this.getDateStatus) {
+ var status = this.getDateStatus(date, year, month, iday);
+ if (this.getDateToolTip) {
+ var toolTip = this.getDateToolTip(date, year, month, iday);
+ if (toolTip)
+ cell.title = toolTip;
+ }
+ if (status === true) {
+ cell.className += " disabled";
+ cell.disabled = true;
+ } else {
+ if (/disabled/i.test(status))
+ cell.disabled = true;
+ cell.className += " " + status;
+ }
+ }
+ if (!cell.disabled) {
+ cell.caldate = new Date(date);
+ cell.ttip = "_";
+ if (!this.multiple && current_month
+ && iday == mday && this.hiliteToday) {
+ cell.className += " selected";
+ this.currentDateEl = cell;
+ }
+ if (date.getFullYear() == TY &&
+ date.getMonth() == TM &&
+ iday == TD) {
+ cell.className += " today";
+ cell.ttip += Calendar._TT["PART_TODAY"];
+ }
+ if (weekend.indexOf(wday.toString()) != -1)
+ cell.className += cell.otherMonth ? " oweekend" : " weekend";
+ }
+ }
+ if (!(hasdays || this.showsOtherMonths))
+ row.className = "emptyrow";
+ }
+ this.title.innerHTML = Calendar._MN[month] + ", " + year;
+ this.onSetTime();
+ this.table.style.visibility = "visible";
+ this._initMultipleDates();
+ // PROFILE
+ // this.tooltips.innerHTML = "Generated in " + ((new Date()) - today) + " ms";
+};
+
+Calendar.prototype._initMultipleDates = function() {
+ if (this.multiple) {
+ for (var i in this.multiple) {
+ var cell = this.datesCells[i];
+ var d = this.multiple[i];
+ if (!d)
+ continue;
+ if (cell)
+ cell.className += " selected";
+ }
+ }
+};
+
+Calendar.prototype._toggleMultipleDate = function(date) {
+ if (this.multiple) {
+ var ds = date.print("%Y%m%d");
+ var cell = this.datesCells[ds];
+ if (cell) {
+ var d = this.multiple[ds];
+ if (!d) {
+ Calendar.addClass(cell, "selected");
+ this.multiple[ds] = date;
+ } else {
+ Calendar.removeClass(cell, "selected");
+ delete this.multiple[ds];
+ }
+ }
+ }
+};
+
+Calendar.prototype.setDateToolTipHandler = function (unaryFunction) {
+ this.getDateToolTip = unaryFunction;
+};
+
+/**
+ * Calls _init function above for going to a certain date (but only if the
+ * date is different than the currently selected one).
+ */
+Calendar.prototype.setDate = function (date) {
+ if (!date.equalsTo(this.date)) {
+ this._init(this.firstDayOfWeek, date);
+ }
+};
+
+/**
+ * Refreshes the calendar. Useful if the "disabledHandler" function is
+ * dynamic, meaning that the list of disabled date can change at runtime.
+ * Just * call this function if you think that the list of disabled dates
+ * should * change.
+ */
+Calendar.prototype.refresh = function () {
+ this._init(this.firstDayOfWeek, this.date);
+};
+
+/** Modifies the "firstDayOfWeek" parameter (pass 0 for Synday, 1 for Monday, etc.). */
+Calendar.prototype.setFirstDayOfWeek = function (firstDayOfWeek) {
+ this._init(firstDayOfWeek, this.date);
+ this._displayWeekdays();
+};
+
+/**
+ * Allows customization of what dates are enabled. The "unaryFunction"
+ * parameter must be a function object that receives the date (as a JS Date
+ * object) and returns a boolean value. If the returned value is true then
+ * the passed date will be marked as disabled.
+ */
+Calendar.prototype.setDateStatusHandler = Calendar.prototype.setDisabledHandler = function (unaryFunction) {
+ this.getDateStatus = unaryFunction;
+};
+
+/** Customization of allowed year range for the calendar. */
+Calendar.prototype.setRange = function (a, z) {
+ this.minYear = a;
+ this.maxYear = z;
+};
+
+/** Calls the first user handler (selectedHandler). */
+Calendar.prototype.callHandler = function () {
+ if (this.onSelected) {
+ this.onSelected(this, this.date.print(this.dateFormat));
+ }
+};
+
+/** Calls the second user handler (closeHandler). */
+Calendar.prototype.callCloseHandler = function () {
+ if (this.onClose) {
+ this.onClose(this);
+ }
+ this.hideShowCovered();
+};
+
+/** Removes the calendar object from the DOM tree and destroys it. */
+Calendar.prototype.destroy = function () {
+ var el = this.element.parentNode;
+ el.removeChild(this.element);
+ Calendar._C = null;
+ window._dynarch_popupCalendar = null;
+};
+
+/**
+ * Moves the calendar element to a different section in the DOM tree (changes
+ * its parent).
+ */
+Calendar.prototype.reparent = function (new_parent) {
+ var el = this.element;
+ el.parentNode.removeChild(el);
+ new_parent.appendChild(el);
+};
+
+// This gets called when the user presses a mouse button anywhere in the
+// document, if the calendar is shown. If the click was outside the open
+// calendar this function closes it.
+Calendar._checkCalendar = function(ev) {
+ var calendar = window._dynarch_popupCalendar;
+ if (!calendar) {
+ return false;
+ }
+ var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
+ for (; el != null && el != calendar.element; el = el.parentNode);
+ if (el == null) {
+ // calls closeHandler which should hide the calendar.
+ window._dynarch_popupCalendar.callCloseHandler();
+ return Calendar.stopEvent(ev);
+ }
+};
+
+/** Shows the calendar. */
+Calendar.prototype.show = function () {
+ var rows = this.table.getElementsByTagName("tr");
+ for (var i = rows.length; i > 0;) {
+ var row = rows[--i];
+ Calendar.removeClass(row, "rowhilite");
+ var cells = row.getElementsByTagName("td");
+ for (var j = cells.length; j > 0;) {
+ var cell = cells[--j];
+ Calendar.removeClass(cell, "hilite");
+ Calendar.removeClass(cell, "active");
+ }
+ }
+ this.element.style.display = "block";
+ this.hidden = false;
+ if (this.isPopup) {
+ window._dynarch_popupCalendar = this;
+ Calendar.addEvent(document, "keydown", Calendar._keyEvent);
+ Calendar.addEvent(document, "keypress", Calendar._keyEvent);
+ Calendar.addEvent(document, "mousedown", Calendar._checkCalendar);
+ }
+ this.hideShowCovered();
+};
+
+/**
+ * Hides the calendar. Also removes any "hilite" from the class of any TD
+ * element.
+ */
+Calendar.prototype.hide = function () {
+ if (this.isPopup) {
+ Calendar.removeEvent(document, "keydown", Calendar._keyEvent);
+ Calendar.removeEvent(document, "keypress", Calendar._keyEvent);
+ Calendar.removeEvent(document, "mousedown", Calendar._checkCalendar);
+ }
+ this.element.style.display = "none";
+ this.hidden = true;
+ this.hideShowCovered();
+};
+
+/**
+ * Shows the calendar at a given absolute position (beware that, depending on
+ * the calendar element style -- position property -- this might be relative
+ * to the parent's containing rectangle).
+ */
+Calendar.prototype.showAt = function (x, y) {
+ var s = this.element.style;
+ s.left = x + "px";
+ s.top = y + "px";
+ this.show();
+};
+
+/** Shows the calendar near a given element. */
+Calendar.prototype.showAtElement = function (el, opts) {
+ var self = this;
+ var p = Calendar.getAbsolutePos(el);
+ if (!opts || typeof opts != "string") {
+ this.showAt(p.x, p.y + el.offsetHeight);
+ return true;
+ }
+ function fixPosition(box) {
+ if (box.x < 0)
+ box.x = 0;
+ if (box.y < 0)
+ box.y = 0;
+ var cp = document.createElement("div");
+ var s = cp.style;
+ s.position = "absolute";
+ s.right = s.bottom = s.width = s.height = "0px";
+ document.body.appendChild(cp);
+ var br = Calendar.getAbsolutePos(cp);
+ document.body.removeChild(cp);
+ if (Calendar.is_ie) {
+ br.y += document.body.scrollTop;
+ br.x += document.body.scrollLeft;
+ } else {
+ br.y += window.scrollY;
+ br.x += window.scrollX;
+ }
+ var tmp = box.x + box.width - br.x;
+ if (tmp > 0) box.x -= tmp;
+ tmp = box.y + box.height - br.y;
+ if (tmp > 0) box.y -= tmp;
+ };
+ this.element.style.display = "block";
+ Calendar.continuation_for_the_fucking_khtml_browser = function() {
+ var w = self.element.offsetWidth;
+ var h = self.element.offsetHeight;
+ self.element.style.display = "none";
+ var valign = opts.substr(0, 1);
+ var halign = "l";
+ if (opts.length > 1) {
+ halign = opts.substr(1, 1);
+ }
+ // vertical alignment
+ switch (valign) {
+ case "T": p.y -= h; break;
+ case "B": p.y += el.offsetHeight; break;
+ case "C": p.y += (el.offsetHeight - h) / 2; break;
+ case "t": p.y += el.offsetHeight - h; break;
+ case "b": break; // already there
+ }
+ // horizontal alignment
+ switch (halign) {
+ case "L": p.x -= w; break;
+ case "R": p.x += el.offsetWidth; break;
+ case "C": p.x += (el.offsetWidth - w) / 2; break;
+ case "l": p.x += el.offsetWidth - w; break;
+ case "r": break; // already there
+ }
+ p.width = w;
+ p.height = h + 40;
+ self.monthsCombo.style.display = "none";
+ fixPosition(p);
+ self.showAt(p.x, p.y);
+ };
+ if (Calendar.is_khtml)
+ setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()", 10);
+ else
+ Calendar.continuation_for_the_fucking_khtml_browser();
+};
+
+/** Customizes the date format. */
+Calendar.prototype.setDateFormat = function (str) {
+ this.dateFormat = str;
+};
+
+/** Customizes the tooltip date format. */
+Calendar.prototype.setTtDateFormat = function (str) {
+ this.ttDateFormat = str;
+};
+
+/**
+ * Tries to identify the date represented in a string. If successful it also
+ * calls this.setDate which moves the calendar to the given date.
+ */
+Calendar.prototype.parseDate = function(str, fmt) {
+ if (!fmt)
+ fmt = this.dateFormat;
+ this.setDate(Date.parseDate(str, fmt));
+};
+
+Calendar.prototype.hideShowCovered = function () {
+ if (!Calendar.is_ie && !Calendar.is_opera)
+ return;
+ function getVisib(obj){
+ var value = obj.style.visibility;
+ if (!value) {
+ if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C
+ if (!Calendar.is_khtml)
+ value = document.defaultView.
+ getComputedStyle(obj, "").getPropertyValue("visibility");
+ else
+ value = '';
+ } else if (obj.currentStyle) { // IE
+ value = obj.currentStyle.visibility;
+ } else
+ value = '';
+ }
+ return value;
+ };
+
+ var tags = new Array("applet", "iframe", "select");
+ var el = this.element;
+
+ var p = Calendar.getAbsolutePos(el);
+ var EX1 = p.x;
+ var EX2 = el.offsetWidth + EX1;
+ var EY1 = p.y;
+ var EY2 = el.offsetHeight + EY1;
+
+ for (var k = tags.length; k > 0; ) {
+ var ar = document.getElementsByTagName(tags[--k]);
+ var cc = null;
+
+ for (var i = ar.length; i > 0;) {
+ cc = ar[--i];
+
+ p = Calendar.getAbsolutePos(cc);
+ var CX1 = p.x;
+ var CX2 = cc.offsetWidth + CX1;
+ var CY1 = p.y;
+ var CY2 = cc.offsetHeight + CY1;
+
+ if (this.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
+ if (!cc.__msh_save_visibility) {
+ cc.__msh_save_visibility = getVisib(cc);
+ }
+ cc.style.visibility = cc.__msh_save_visibility;
+ } else {
+ if (!cc.__msh_save_visibility) {
+ cc.__msh_save_visibility = getVisib(cc);
+ }
+ cc.style.visibility = "hidden";
+ }
+ }
+ }
+};
+
+/** Internal function; it displays the bar with the names of the weekday. */
+Calendar.prototype._displayWeekdays = function () {
+ var fdow = this.firstDayOfWeek;
+ var cell = this.firstdayname;
+ var weekend = Calendar._TT["WEEKEND"];
+ for (var i = 0; i < 7; ++i) {
+ cell.className = "day name";
+ var realday = (i + fdow) % 7;
+ if (i) {
+ cell.ttip = Calendar._TT["DAY_FIRST"].replace("%s", Calendar._DN[realday]);
+ cell.navtype = 100;
+ cell.calendar = this;
+ cell.fdow = realday;
+ Calendar._add_evs(cell);
+ }
+ if (weekend.indexOf(realday.toString()) != -1) {
+ Calendar.addClass(cell, "weekend");
+ }
+ cell.innerHTML = Calendar._SDN[(i + fdow) % 7];
+ cell = cell.nextSibling;
+ }
+};
+
+/** Internal function. Hides all combo boxes that might be displayed. */
+Calendar.prototype._hideCombos = function () {
+ this.monthsCombo.style.display = "none";
+ this.yearsCombo.style.display = "none";
+};
+
+/** Internal function. Starts dragging the element. */
+Calendar.prototype._dragStart = function (ev) {
+ if (this.dragging) {
+ return;
+ }
+ this.dragging = true;
+ var posX;
+ var posY;
+ if (Calendar.is_ie) {
+ posY = window.event.clientY + document.body.scrollTop;
+ posX = window.event.clientX + document.body.scrollLeft;
+ } else {
+ posY = ev.clientY + window.scrollY;
+ posX = ev.clientX + window.scrollX;
+ }
+ var st = this.element.style;
+ this.xOffs = posX - parseInt(st.left);
+ this.yOffs = posY - parseInt(st.top);
+ with (Calendar) {
+ addEvent(document, "mousemove", calDragIt);
+ addEvent(document, "mouseup", calDragEnd);
+ }
+};
+
+// BEGIN: DATE OBJECT PATCHES
+
+/** Adds the number of days array to the Date object. */
+Date._MD = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
+
+/** Constants used for time computations */
+Date.SECOND = 1000 /* milliseconds */;
+Date.MINUTE = 60 * Date.SECOND;
+Date.HOUR = 60 * Date.MINUTE;
+Date.DAY = 24 * Date.HOUR;
+Date.WEEK = 7 * Date.DAY;
+
+Date.parseDate = function(str, fmt) {
+ var today = new Date();
+ var y = 0;
+ var m = -1;
+ var d = 0;
+ var a = str.split(/\W+/);
+ var b = fmt.match(/%./g);
+ var i = 0, j = 0;
+ var hr = 0;
+ var min = 0;
+ for (i = 0; i < a.length; ++i) {
+ if (!a[i])
+ continue;
+ switch (b[i]) {
+ case "%d":
+ case "%e":
+ d = parseInt(a[i], 10);
+ break;
+
+ case "%m":
+ m = parseInt(a[i], 10) - 1;
+ break;
+
+ case "%Y":
+ case "%y":
+ y = parseInt(a[i], 10);
+ (y < 100) && (y += (y > 29) ? 1900 : 2000);
+ break;
+
+ case "%b":
+ case "%B":
+ for (j = 0; j < 12; ++j) {
+ if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
+ }
+ break;
+
+ case "%H":
+ case "%I":
+ case "%k":
+ case "%l":
+ hr = parseInt(a[i], 10);
+ break;
+
+ case "%P":
+ case "%p":
+ if (/pm/i.test(a[i]) && hr < 12)
+ hr += 12;
+ else if (/am/i.test(a[i]) && hr >= 12)
+ hr -= 12;
+ break;
+
+ case "%M":
+ min = parseInt(a[i], 10);
+ break;
+ }
+ }
+ if (isNaN(y)) y = today.getFullYear();
+ if (isNaN(m)) m = today.getMonth();
+ if (isNaN(d)) d = today.getDate();
+ if (isNaN(hr)) hr = today.getHours();
+ if (isNaN(min)) min = today.getMinutes();
+ if (y != 0 && m != -1 && d != 0)
+ return new Date(y, m, d, hr, min, 0);
+ y = 0; m = -1; d = 0;
+ for (i = 0; i < a.length; ++i) {
+ if (a[i].search(/[a-zA-Z]+/) != -1) {
+ var t = -1;
+ for (j = 0; j < 12; ++j) {
+ if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }
+ }
+ if (t != -1) {
+ if (m != -1) {
+ d = m+1;
+ }
+ m = t;
+ }
+ } else if (parseInt(a[i], 10) <= 12 && m == -1) {
+ m = a[i]-1;
+ } else if (parseInt(a[i], 10) > 31 && y == 0) {
+ y = parseInt(a[i], 10);
+ (y < 100) && (y += (y > 29) ? 1900 : 2000);
+ } else if (d == 0) {
+ d = a[i];
+ }
+ }
+ if (y == 0)
+ y = today.getFullYear();
+ if (m != -1 && d != 0)
+ return new Date(y, m, d, hr, min, 0);
+ return today;
+};
+
+/** Returns the number of days in the current month */
+Date.prototype.getMonthDays = function(month) {
+ var year = this.getFullYear();
+ if (typeof month == "undefined") {
+ month = this.getMonth();
+ }
+ if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
+ return 29;
+ } else {
+ return Date._MD[month];
+ }
+};
+
+/** Returns the number of day in the year. */
+Date.prototype.getDayOfYear = function() {
+ var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
+ var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
+ var time = now - then;
+ return Math.floor(time / Date.DAY);
+};
+
+/** Returns the number of the week in year, as defined in ISO 8601. */
+Date.prototype.getWeekNumber = function() {
+ var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
+ var DoW = d.getDay();
+ d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
+ var ms = d.valueOf(); // GMT
+ d.setMonth(0);
+ d.setDate(4); // Thu in Week 1
+ return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
+};
+
+/** Checks date and time equality */
+Date.prototype.equalsTo = function(date) {
+ return ((this.getFullYear() == date.getFullYear()) &&
+ (this.getMonth() == date.getMonth()) &&
+ (this.getDate() == date.getDate()) &&
+ (this.getHours() == date.getHours()) &&
+ (this.getMinutes() == date.getMinutes()));
+};
+
+/** Set only the year, month, date parts (keep existing time) */
+Date.prototype.setDateOnly = function(date) {
+ var tmp = new Date(date);
+ this.setDate(1);
+ this.setFullYear(tmp.getFullYear());
+ this.setMonth(tmp.getMonth());
+ this.setDate(tmp.getDate());
+};
+
+/** Prints the date in a string according to the given format. */
+Date.prototype.print = function (str) {
+ var m = this.getMonth();
+ var d = this.getDate();
+ var y = this.getFullYear();
+ var wn = this.getWeekNumber();
+ var w = this.getDay();
+ var s = {};
+ var hr = this.getHours();
+ var pm = (hr >= 12);
+ var ir = (pm) ? (hr - 12) : hr;
+ var dy = this.getDayOfYear();
+ if (ir == 0)
+ ir = 12;
+ var min = this.getMinutes();
+ var sec = this.getSeconds();
+ s["%a"] = Calendar._SDN[w]; // abbreviated weekday name [FIXME: I18N]
+ s["%A"] = Calendar._DN[w]; // full weekday name
+ s["%b"] = Calendar._SMN[m]; // abbreviated month name [FIXME: I18N]
+ s["%B"] = Calendar._MN[m]; // full month name
+ // FIXME: %c : preferred date and time representation for the current locale
+ s["%C"] = 1 + Math.floor(y / 100); // the century number
+ s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31)
+ s["%e"] = d; // the day of the month (range 1 to 31)
+ // FIXME: %D : american date style: %m/%d/%y
+ // FIXME: %E, %F, %G, %g, %h (man strftime)
+ s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format)
+ s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format)
+ s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366)
+ s["%k"] = hr; // hour, range 0 to 23 (24h format)
+ s["%l"] = ir; // hour, range 1 to 12 (12h format)
+ s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12
+ s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
+ s["%n"] = "\n"; // a newline character
+ s["%p"] = pm ? "PM" : "AM";
+ s["%P"] = pm ? "pm" : "am";
+ // FIXME: %r : the time in am/pm notation %I:%M:%S %p
+ // FIXME: %R : the time in 24-hour notation %H:%M
+ s["%s"] = Math.floor(this.getTime() / 1000);
+ s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59
+ s["%t"] = "\t"; // a tab character
+ // FIXME: %T : the time in 24-hour notation (%H:%M:%S)
+ s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn;
+ s["%u"] = w + 1; // the day of the week (range 1 to 7, 1 = MON)
+ s["%w"] = w; // the day of the week (range 0 to 6, 0 = SUN)
+ // FIXME: %x : preferred date representation for the current locale without the time
+ // FIXME: %X : preferred time representation for the current locale without the date
+ s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99)
+ s["%Y"] = y; // year with the century
+ s["%%"] = "%"; // a literal '%' character
+
+ var re = /%./g;
+ if (!Calendar.is_ie5 && !Calendar.is_khtml)
+ return str.replace(re, function (par) { return s[par] || par; });
+
+ var a = str.match(re);
+ for (var i = 0; i < a.length; i++) {
+ var tmp = s[a[i]];
+ if (tmp) {
+ re = new RegExp(a[i], 'g');
+ str = str.replace(re, tmp);
+ }
+ }
+
+ return str;
+};
+
+Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear;
+Date.prototype.setFullYear = function(y) {
+ var d = new Date(this);
+ d.__msh_oldSetFullYear(y);
+ if (d.getMonth() != this.getMonth())
+ this.setDate(28);
+ this.__msh_oldSetFullYear(y);
+};
+
+// END: DATE OBJECT PATCHES
+
+
+// global object that remembers the calendar
+window._dynarch_popupCalendar = null;
diff --git a/application/media/js/dhtml.date_selector.js b/application/media/js/dhtml.date_selector.js
new file mode 100644
index 00000000..3050c624
--- /dev/null
+++ b/application/media/js/dhtml.date_selector.js
@@ -0,0 +1,76 @@
+var defaults = new Array();
+function dateSelector(id) {
+ var el = document.getElementById(id);
+ var format = gettype(el.id);
+ var epoch;
+ var parse = false;
+
+ var cal = new Calendar(0, null, onSelect, onClose);
+
+ if (defaults['f_time_'+id]) {
+ cal.showsTime = true;
+ } else {
+ cal.showsTime = false;
+ }
+
+ cal.weekNumbers = true;
+ cal.showsOtherMonths = true;
+ cal.create();
+
+ // convert to milliseconds (Epoch is usually expressed in seconds, but Javascript uses Milliseconds)
+ switch (format) {
+ case '%es' : epoch = el.value * 86400 * 1000;
+ format = '%s';
+ parse = true;
+ break;
+ case '%s' : epoch = el.value * 1000;
+ parse = true;
+ break;
+ }
+
+ // Convert the value to the date so that the calendar will display it
+ if (parse) {
+ var dDate = new Date();
+ dDate.setTime(epoch);
+ cal.setDateFormat('%a, %d %b %Y'); // set the specified date format
+ cal.parseDate(dDate.toString()); // try to parse the text in field
+ cal.setDateFormat(format); // set the specified date format
+ } else {
+ cal.setDateFormat(format); // set the specified date format
+ cal.parseDate(el.value); // try to parse the text in field
+ }
+
+ cal.sel = el; // inform it what input field we use
+ cal.showAtElement(el, 'BR'); // show the calendar
+}
+
+function onSelect(calendar,date) {
+ switch (gettype(calendar.sel.id)) {
+ case '%es' : date = Math.round(date / 86400);
+ break;
+ }
+
+ calendar.sel.value = date;
+ if (calendar.dateClicked)
+ onClose(calendar);
+}
+
+function onClose(calendar,date) {
+ calendar.hide();
+}
+
+function gettype(attr) {
+ if (typeof defaults == "undefined") {
+ return '%s';
+ }
+
+ if (typeof defaults[attr] == "undefined") {
+ if (typeof default_date_format == "undefined") {
+ return '%s';
+ } else {
+ return default_date_format;
+ }
+ } else {
+ return defaults[attr];
+ }
+}
diff --git a/application/media/js/jquery-1.6.4.min.js b/application/media/js/jquery-1.6.4.min.js
new file mode 100644
index 00000000..628ed9b3
--- /dev/null
+++ b/application/media/js/jquery-1.6.4.min.js
@@ -0,0 +1,4 @@
+/*! jQuery v1.6.4 http://jquery.com/ | http://jquery.org/license */
+(function(a,b){function cu(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cr(a){if(!cg[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){ch||(ch=c.createElement("iframe"),ch.frameBorder=ch.width=ch.height=0),b.appendChild(ch);if(!ci||!ch.createElement)ci=(ch.contentWindow||ch.contentDocument).document,ci.write((c.compatMode==="CSS1Compat"?"":"")+""),ci.close();d=ci.createElement(a),ci.body.appendChild(d),e=f.css(d,"display"),b.removeChild(ch)}cg[a]=e}return cg[a]}function cq(a,b){var c={};f.each(cm.concat.apply([],cm.slice(0,b)),function(){c[this]=a});return c}function cp(){cn=b}function co(){setTimeout(cp,0);return cn=f.now()}function cf(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ce(){try{return new a.XMLHttpRequest}catch(b){}}function b$(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){c!=="border"&&f.each(e,function(){c||(d-=parseFloat(f.css(a,"padding"+this))||0),c==="margin"?d+=parseFloat(f.css(a,c+this))||0:d-=parseFloat(f.css(a,"border"+this+"Width"))||0});return d+"px"}d=bv(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0,c&&f.each(e,function(){d+=parseFloat(f.css(a,"padding"+this))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+this+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+this))||0)});return d+"px"}function bl(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bd,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bk(a){f.nodeName(a,"input")?bj(a):"getElementsByTagName"in a&&f.grep(a.getElementsByTagName("input"),bj)}function bj(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bi(a){return"getElementsByTagName"in a?a.getElementsByTagName("*"):"querySelectorAll"in a?a.querySelectorAll("*"):[]}function bh(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bg(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c=f.expando,d=f.data(a),e=f.data(b,d);if(d=d[c]){var g=d.events;e=e[c]=f.extend({},d);if(g){delete e.handle,e.events={};for(var h in g)for(var i=0,j=g[h].length;i=0===c})}function U(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function M(a,b){return(a&&a!=="*"?a+".":"")+b.replace(y,"`").replace(z,"&")}function L(a){var b,c,d,e,g,h,i,j,k,l,m,n,o,p=[],q=[],r=f._data(this,"events");if(!(a.liveFired===this||!r||!r.live||a.target.disabled||a.button&&a.type==="click")){a.namespace&&(n=new RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)")),a.liveFired=this;var s=r.live.slice(0);for(i=0;ic)break;a.currentTarget=e.elem,a.data=e.handleObj.data,a.handleObj=e.handleObj,o=e.handleObj.origHandler.apply(e.elem,arguments);if(o===!1||a.isPropagationStopped()){c=e.level,o===!1&&(b=!1);if(a.isImmediatePropagationStopped())break}}return b}}function J(a,c,d){var e=f.extend({},d[0]);e.type=a,e.originalEvent={},e.liveFired=b,f.event.handle.call(c,e),e.isDefaultPrevented()&&d[0].preventDefault()}function D(){return!0}function C(){return!1}function m(a,c,d){var e=c+"defer",g=c+"queue",h=c+"mark",i=f.data(a,e,b,!0);i&&(d==="queue"||!f.data(a,g,b,!0))&&(d==="mark"||!f.data(a,h,b,!0))&&setTimeout(function(){!f.data(a,g,b,!0)&&!f.data(a,h,b,!0)&&(f.removeData(a,e,!0),i.resolve())},0)}function l(a){for(var b in a)if(b!=="toJSON")return!1;return!0}function k(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(j,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNaN(d)?i.test(d)?f.parseJSON(d):d:parseFloat(d)}catch(g){}f.data(a,c,d)}else d=b}return d}var c=a.document,d=a.navigator,e=a.location,f=function(){function K(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(K,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/\d/,n=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,o=/^[\],:{}\s]*$/,p=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,q=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,r=/(?:^|:|,)(?:\s*\[)+/g,s=/(webkit)[ \/]([\w.]+)/,t=/(opera)(?:.*version)?[ \/]([\w.]+)/,u=/(msie) ([\w.]+)/,v=/(mozilla)(?:.*? rv:([\w.]+))?/,w=/-([a-z]|[0-9])/ig,x=/^-ms-/,y=function(a,b){return(b+"").toUpperCase()},z=d.userAgent,A,B,C,D=Object.prototype.toString,E=Object.prototype.hasOwnProperty,F=Array.prototype.push,G=Array.prototype.slice,H=String.prototype.trim,I=Array.prototype.indexOf,J={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=n.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.6.4",length:0,size:function(){return this.length},toArray:function(){return G.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?F.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),B.done(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(G.apply(this,arguments),"slice",G.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:F,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;B.resolveWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!B){B=e._Deferred();if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",C,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",C),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&K()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNaN:function(a){return a==null||!m.test(a)||isNaN(a)},type:function(a){return a==null?String(a):J[D.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!E.call(a,"constructor")&&!E.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||E.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(o.test(b.replace(p,"@").replace(q,"]").replace(r,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(x,"ms-").replace(w,y)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?h.call(arguments,0):c,--e||g.resolveWith(g,h.call(b,0))}}var b=arguments,c=0,d=b.length,e=d,g=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred();if(d>1){for(;c
a",d=a.getElementsByTagName("*"),e=a.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=a.getElementsByTagName("input")[0],k={leadingWhitespace:a.firstChild.nodeType===3,tbody:!a.getElementsByTagName("tbody").length,htmlSerialize:!!a.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55$/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:a.className!=="t",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,k.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,k.optDisabled=!h.disabled;try{delete a.test}catch(v){k.deleteExpando=!1}!a.addEventListener&&a.attachEvent&&a.fireEvent&&(a.attachEvent("onclick",function(){k.noCloneEvent=!1}),a.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),k.radioValue=i.value==="t",i.setAttribute("checked","checked"),a.appendChild(i),l=c.createDocumentFragment(),l.appendChild(a.firstChild),k.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,a.innerHTML="",a.style.width=a.style.paddingLeft="1px",m=c.getElementsByTagName("body")[0],o=c.createElement(m?"div":"body"),p={visibility:"hidden",width:0,height:0,border:0,margin:0,background:"none"},m&&f.extend(p,{position:"absolute",left:"-1000px",top:"-1000px"});for(t in p)o.style[t]=p[t];o.appendChild(a),n=m||b,n.insertBefore(o,n.firstChild),k.appendChecked=i.checked,k.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,k.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="",k.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="